Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/zip_source_crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,15 @@ static zip_int64_t crc_read(zip_source_t *src, void *_ctx, void *data, zip_uint6
/* TODO: Set comp_size, comp_method, encryption_method?
After all, this only works for uncompressed data. */
st->size = ctx->size;
st->crc = ctx->crc;
st->comp_size = ctx->size;
st->comp_method = ZIP_CM_STORE;
st->encryption_method = ZIP_EM_NONE;
st->valid |= ZIP_STAT_SIZE | ZIP_STAT_CRC | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
st->valid |= ZIP_STAT_SIZE | ZIP_STAT_COMP_SIZE | ZIP_STAT_COMP_METHOD | ZIP_STAT_ENCRYPTION_METHOD;
/* When validating, don't report a CRC for data that has none (WinZip AES AE-2). */
if (!ctx->validate || (st->valid & ZIP_STAT_CRC)) {
st->crc = ctx->crc;
st->valid |= ZIP_STAT_CRC;
}
}
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/zip_source_zip_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ ZIP_EXTERN zip_source_t *zip_source_zip_file_create(zip_t *srcza, zip_uint64_t s
needs_decrypt = ((flags & ZIP_FL_ENCRYPTED) == 0) && encrypted;
compressed = (st.valid & ZIP_STAT_COMP_METHOD) && (st.comp_method != ZIP_CM_STORE);
needs_decompress = ((flags & ZIP_FL_COMPRESSED) == 0) && compressed;
/* when reading the whole file, check for CRC errors */
needs_crc = ((flags & ZIP_FL_COMPRESSED) == 0 || !compressed) && !partial_data && (st.valid & ZIP_STAT_CRC) != 0;
/* when reading the whole file, check for CRC errors; for decrypted data without CRC (WinZip AES AE-2), still check the length */
needs_crc = ((flags & ZIP_FL_COMPRESSED) == 0 || !compressed) && !partial_data && ((st.valid & ZIP_STAT_CRC) != 0 || needs_decrypt);

if (needs_decrypt) {
if (password == NULL) {
Expand Down
Binary file added regress/data/incons-aes-ae2-data-longer.zip
Binary file not shown.
Binary file added regress/data/incons-aes-ae2-data-shorter.zip
Binary file not shown.
11 changes: 11 additions & 0 deletions regress/read_incons_aes_ae2_longer.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# WinZip AES AE-2 entry (no CRC) decrypts to more data than the uncompressed size in its header
features HAVE_CRYPTO
arguments test.zip set_password foofoofoo cat 1
return 1
file test.zip incons-aes-ae2-data-longer.zip
stdout
encrypted
end-of-inline-data
stderr
can't read file at index '1': Zip archive inconsistent: file length in header doesn't match actual file length
end-of-inline-data
11 changes: 11 additions & 0 deletions regress/read_incons_aes_ae2_shorter.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# WinZip AES AE-2 entry (no CRC) decrypts to less data than the uncompressed size in its header
features HAVE_CRYPTO
arguments test.zip set_password foofoofoo cat 1
return 1
file test.zip incons-aes-ae2-data-shorter.zip
stdout
encrypted
end-of-inline-data
stderr
can't read file at index '1': Zip archive inconsistent: file length in header doesn't match actual file length
end-of-inline-data