diff --git a/ChangeLog b/ChangeLog index f7eab737e..42b70eb33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Dec 27 14:21:52 GMT 2007 (trog) +----------------------------------- + * libclamav/chmunpack.c: fix bb#740 + Wed Dec 26 14:49:12 CET 2007 (acab) ----------------------------------- * libclamav/wwunpack.c: fix typo causing SEGV - bb#743 diff --git a/libclamav/chmunpack.c b/libclamav/chmunpack.c index bbb10e688..023f2e81b 100644 --- a/libclamav/chmunpack.c +++ b/libclamav/chmunpack.c @@ -419,7 +419,7 @@ static int prepare_file(int fd, chm_metadata_t *metadata) { uint64_t name_len, section; - while (metadata->chunk_entries--) { + while (metadata->chunk_entries != 0) { if (metadata->chunk_current >= metadata->chunk_end) { return CL_EFORMAT; } @@ -433,7 +433,8 @@ static int prepare_file(int fd, chm_metadata_t *metadata) metadata->chunk_current += name_len; section = read_enc_int(&metadata->chunk_current, metadata->chunk_end); metadata->file_offset = read_enc_int(&metadata->chunk_current, metadata->chunk_end); - metadata->file_length = read_enc_int(&metadata->chunk_current, metadata->chunk_end); + metadata->file_length = read_enc_int(&metadata->chunk_current, metadata->chunk_end); + metadata->chunk_entries--; if (section == 1) { return CL_SUCCESS; } @@ -836,16 +837,20 @@ int cli_chm_prepare_file(int fd, char *dirname, chm_metadata_t *metadata) cli_dbgmsg("in cli_chm_prepare_file\n"); - if (metadata->chunk_entries == 0) { - if (metadata->num_chunks == 0) { - return CL_BREAK; - } - if ((retval = read_chunk(metadata, fd)) != CL_SUCCESS) { - return retval; + do { + if (metadata->chunk_entries == 0) { + if (metadata->num_chunks == 0) { + return CL_BREAK; + } + if ((retval = read_chunk(metadata, fd)) != CL_SUCCESS) { + return retval; + } + metadata->num_chunks--; + metadata->chunk_offset += metadata->itsp_hdr.block_len; } - } - - return prepare_file(fd, metadata); + retval = prepare_file(fd, metadata); + } while (retval == CL_BREAK); /* Ran out of chunk entries before finding a file */ + return retval; } int cli_chm_open(int fd, const char *dirname, chm_metadata_t *metadata)