Skip to content

Use source compression metadata when reading pending buffer entries - #613

Open
fhgffy wants to merge 1 commit into
nih-at:mainfrom
fhgffy:fix/pending-buffer-compression-read
Open

fhgffy wants to merge 1 commit into
nih-at:mainfrom
fhgffy:fix/pending-buffer-compression-read

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 4, 2026

Copy link
Copy Markdown

Reading an added or replaced zip_source_buffer entry after setting ZIP_CM_DEFLATE, but before zip_close(), fails with a Zlib data error. The read pipeline uses the pending output compression method even though the source still contains uncompressed bytes.

For changed entries, obtain the compression method, compressed size and their validity bits from the underlying source when preparing the read pipeline. Keep the public zip_stat_index() metadata and the other entry attributes. Add regressions for new and replaced buffers, partial and repeated reads, and empty data.

Validation on 88b98af764442d6de1b38a26bee5e6f6a33c2c67:

  • With the original library, the new and replacement regressions fail with Zlib data errors; the empty-buffer control and 12 existing lifecycle regressions pass.
  • With the fix, all 15 selected regressions pass with no skips: the three new cases plus existing reopen, unchanged/multiple-open, read, seek, source-seek and fdopen cases.
  • A public API probe fails on the original library and passes with the fix: six buffer/method combinations each verify two full reads, EOF, close and pending name/index/mtime/compression metadata. Three ordinary-file rejection controls also pass.
  • A separate probe covers six buffer/method combinations with two file handles still open when the archive is discarded. The fixed library passes both read-then-close and direct-close paths. The original DEFLATE cases return ZIP_ER_INTERNAL from close after the discarded read reports ZIP_ER_ZIPCLOSED.
  • The patch applies cleanly to this base, and git diff --check passes.

Testing used Windows x64, MinGW GCC 15.1, a Debug/static build, zlib and Windows crypto. Optional bzip2/LZMA/XZ/Zstd features were disabled. The complete configured suite was previously run on 05487938a72b47fa783df5b4dabe0869edc51ebc (181 passed, 16 skipped); this newer base received the focused validation above. Linux, ARM, MSVC, sanitizers and continuous fuzzing were not run. Ordinary-file and add-from-zip sources retain their existing changed-read rejection; custom compressed sources supporting REOPEN were not covered.

@fhgffy
fhgffy marked this pull request as ready for review October 4, 2026 19:39
@fhgffy

fhgffy commented Oct 4, 2026

Copy link
Copy Markdown
Author

The two Win32 XZ failures also occur in base build 54833985 at 88b98af, using the same VS 2019/MSVC 19.29 and liblzma 5.8.1 environment as this PR's build. All 194 shared test outcomes match; the three added tests pass.

The ARM Windows and ARM UWP jobs fail during configuration because Windows SDK 10.0.26100.0 ARM support is missing, before libzip is compiled.

@dillof dillof added this to the later milestone Oct 5, 2026
@dillof dillof added the bug For issues, use type instead. label Oct 5, 2026

This branch has not been deployed

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

Labels

bug For issues, use type instead.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants