Skip to content

Commit

Permalink
Don’t treat truncated archive comment as error when not checking cons…
Browse files Browse the repository at this point in the history
…istency.
  • Loading branch information
dillof committed Aug 21, 2024
1 parent ab87154 commit 9621ee0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/zip_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,15 @@ static bool _zip_read_cdir(zip_t *za, zip_buffer_t *buffer, zip_uint64_t buf_off
_zip_buffer_set_offset(buffer, eocd_offset + EOCDLEN);
tail_len = _zip_buffer_left(buffer);

if (tail_len < comment_len || ((za->open_flags & ZIP_CHECKCONS) && tail_len != comment_len)) {
zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID);
_zip_cdir_free(cd);
return true;
if (tail_len != comment_len) {
if (za->open_flags & ZIP_CHECKCONS) {
zip_error_set(error, ZIP_ER_INCONS, ZIP_ER_DETAIL_COMMENT_LENGTH_INVALID);
_zip_cdir_free(cd);
return true;
}
if (tail_len < comment_len) {
comment_len = tail_len;
}
}

if (comment_len) {
Expand Down
10 changes: 10 additions & 0 deletions regress/open_archive_comment_wrong.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# zip_open: file with wrong archive comment lentgh, no consistency check: opens fine
program tryopen
arguments incons-archive-comment-longer.zip incons-archive-comment-shorter.zip
return 0
file incons-archive-comment-longer.zip incons-archive-comment-longer.zip
file incons-archive-comment-shorter.zip incons-archive-comment-shorter.zip
stdout
opening 'incons-archive-comment-longer.zip' succeeded, 1 entries
opening 'incons-archive-comment-shorter.zip' succeeded, 1 entries
end-of-inline-data

0 comments on commit 9621ee0

Please sign in to comment.