improve handling of archives with unusual headers

git-svn: trunk@2593
remotes/push_mirror/metadata
Tomasz Kojm 19 years ago
parent af7d0dde01
commit f1452e22aa
  1. 4
      clamav-devel/ChangeLog
  2. 21
      clamav-devel/libclamav/unzip.c

@ -1,3 +1,7 @@
Sun Jan 7 01:24:21 CET 2007 (tk)
---------------------------------
* libclamav/unzip.c: improve handling of archives with unusual headers
Sat Jan 6 17:45:49 CET 2007 (tk)
---------------------------------
* clamd: s/DetectPhishing/PhishingSignatures

@ -168,14 +168,15 @@ int __zip_find_disk_trailer(int fd, off_t filesize, struct zip_disk_trailer *tra
int __zip_parse_root_directory(int fd, struct zip_disk_trailer *trailer, zip_dir_hdr **hdr_return, off_t start)
{
struct zip_root_dirent dirent, *d;
zip_dir_hdr *hdr, *hdr0;
zip_dir_hdr *hdr, *hdr0, *prev_hdr;
uint16_t *p_reclen = NULL, entries;
uint32_t offset;
struct stat sb;
uint16_t u_entries = EC16(trailer->z_entries);
uint32_t u_rootsize = EC32(trailer->z_rootsize);
uint32_t u_rootseek = EC32(trailer->z_rootseek) + start;
uint16_t u_extras, u_comment, u_namlen, u_flags;
uint16_t u_extras, u_comment, u_namlen, u_flags;
uint8_t clone_entry;
char *pt;
@ -196,6 +197,8 @@ int __zip_parse_root_directory(int fd, struct zip_disk_trailer *trailer, zip_dir
hdr = hdr0;
for(entries = u_entries, offset = 0; entries > 0; entries--) {
clone_entry = 0;
if(lseek(fd, u_rootseek + offset, SEEK_SET) < 0) {
free(hdr0);
cli_errmsg("Unzip: __zip_parse_root_directory: Can't lseek descriptor %d\n", fd);
@ -244,6 +247,7 @@ int __zip_parse_root_directory(int fd, struct zip_disk_trailer *trailer, zip_dir
cli_dbgmsg("Unzip: __zip_parse_root_directory: File claims to be deflated but csize == usize\n");
cli_dbgmsg("Unzip: __zip_parse_root_directory: Assuming method 'stored'\n");
hdr->d_compr = 0;
clone_entry = 1;
}
hdr->d_flags = u_flags;
@ -274,7 +278,20 @@ int __zip_parse_root_directory(int fd, struct zip_disk_trailer *trailer, zip_dir
hdr->d_reclen = (uint16_t) (pt - (char *) hdr);
p_reclen = &hdr->d_reclen;
prev_hdr = hdr;
hdr = (zip_dir_hdr *) ((char *) hdr + hdr->d_reclen);
if(clone_entry) {
hdr0 = (zip_dir_hdr *) cli_realloc(hdr0, u_rootsize + *p_reclen);
if(!hdr0)
return CL_EMEM;
memcpy((zip_dir_hdr *) hdr, (zip_dir_hdr *) prev_hdr, *p_reclen);
hdr->d_compr = 8;
if(u_namlen)
hdr->d_name[strlen(hdr->d_name) - 1]++;
p_reclen = &hdr->d_reclen;
hdr = (zip_dir_hdr *) ((char *) hdr + hdr->d_reclen);
}
}
if(p_reclen) {

Loading…
Cancel
Save