Skip to content

Fix comp_size check for partial and unknown-size zip sources - #662

Closed
larancibia wants to merge 1 commit into
nih-at:mainfrom
larancibia:fix/source-zip-partial-comp-size
Closed

larancibia wants to merge 1 commit into
nih-at:mainfrom
larancibia:fix/source-zip-partial-comp-size

Conversation

@larancibia

Copy link
Copy Markdown

In zip_source_zip_file_create(), the stored partial-read bounds check start + (zip_uint64_t)data_len > st.comp_size runs even when ZIP_STAT_COMP_SIZE is not set in st.valid and casts data_len == -1 ("read to end") to ZIP_UINT64_MAX:

  • Reopenable pending sources without ZIP_STAT_COMP_SIZE fail spuriously with ZIP_ER_INCONS (comparing against st.comp_size == 0).
  • Stored sources with valid ZIP_STAT_COMP_SIZE and unknown uncompressed size (data_len == -1) fail spuriously at start == 0 (ZIP_UINT64_MAX > st.comp_size) and wrap start + ZIP_UINT64_MAX to start - 1 when start > 0, missing start == st.comp_size + 1.

Guard the check on have_comp_size, reject start > st.comp_size first, and compare (zip_uint64_t)data_len > st.comp_size - start only when data_len >= 0.

Adds a CMocka run_test_table unit test (regress/programs/source_zip_partial.c) covering pending sources without ZIP_STAT_COMP_SIZE, exact stored boundaries, len == -1 (start <= comp_size vs start > comp_size), start + len > comp_size, and uint64_t wraparound, and sets PATH on CMocka tests so Windows shared-library builds locate zip.dll.

Only enforce st.comp_size in zip_source_zip_file_create() when ZIP_STAT_COMP_SIZE is valid, check start > st.comp_size directly for open-ended reads (data_len < 0) instead of casting -1 to zip_uint64_t, and compare data_len against st.comp_size - start to avoid unsigned wraparound.
@dillof dillof closed this in 06a84ff Nov 27, 2026
@dillof

dillof commented Nov 27, 2026

Copy link
Copy Markdown
Member

Thanks, adapted and committed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants