Skip to content

Commit

Permalink
Account for encryption header in consistency check.
Browse files Browse the repository at this point in the history
Closes #474
  • Loading branch information
dillof committed Dec 11, 2024
1 parent 9ce1c23 commit 3d25095
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions lib/zip_dirent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,10 +1280,31 @@ zip_dirent_torrentzip_normalize(zip_dirent_t *de) {
/* last_mod, extra_fields, and comment are normalized in zip_dirent_write() directly */
}

int
zip_dirent_check_consistency(zip_dirent_t *dirent) {
if (dirent->comp_method == ZIP_CM_STORE && dirent->comp_size != dirent->uncomp_size) {
return ZIP_ER_DETAIL_STORED_SIZE_MISMATCH;
int zip_dirent_check_consistency(zip_dirent_t *dirent) {
if (dirent->comp_method == ZIP_CM_STORE) {
zip_uint64_t header_size = 0;
switch (dirent->encryption_method) {
case ZIP_EM_NONE:
break;
case ZIP_EM_TRAD_PKWARE:
header_size = 12;
break;
case ZIP_EM_AES_128:
header_size = 20;
break;
case ZIP_EM_AES_192:
header_size = 24;
break;
case ZIP_EM_AES_256:
header_size = 28;
break;

default:
return 0;
}
if (dirent->uncomp_size + header_size < dirent->uncomp_size || dirent->comp_size != dirent->uncomp_size + header_size) {
return ZIP_ER_DETAIL_STORED_SIZE_MISMATCH;
}
}
return 0;
}
Expand Down

0 comments on commit 3d25095

Please sign in to comment.