Fix: Parse zip64 extra block by sentinel, not fixed order#19
Open
rayhankinan wants to merge 13 commits intoyeka:masterfrom
Open
Fix: Parse zip64 extra block by sentinel, not fixed order#19rayhankinan wants to merge 13 commits intoyeka:masterfrom
rayhankinan wants to merge 13 commits intoyeka:masterfrom
Conversation
* Fix: Change back to yeka/zip * add test for multipart * add test cases for multipart protected * add test for zip64 format * add test for multipart with multiple files * change approach multifile multipart zip & fix diskNbr check for single file archive * revert approach to previous --------- Co-authored-by: rayhankinan <rayhankinan@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a long-standing parsing bug inherited from upstream
archive/zip. APPNOTE 4.5.3 specifies that the zip64 extra block in a central-directory entry contains only the fields whose 32-bit counterpart was sentinel-promoted (0xFFFFFFFF). The current parser reads the extra in fixedsize, size, offsetorder based purely on remaining length, so it misparses any archive where the fields were promoted asymmetrically — for example an archive larger than 4 GiB whose individual entries are smaller than 4 GiB (only the offset gets promoted).In that case the old parser consumed the offset bytes as
UncompressedSize64and leftf.headerOffsetstuck at0xFFFFFFFF, makingf.Open()fail.Change
reader.go::readDirectoryHeadernow checks each 32-bit counterpart for the sentinel value and consumes the matching 8-byte field only when promotion was indicated. A malformed archive that claims promotion without supplying enough bytes is now rejected withErrFormat.Test plan
TestZip64AsymmetricPromotion— hand-builds an archive (no testdata bytes; constructed in Go from struct fields and known offsets) with one stored entry whose central-directory offset is sentinel-promoted but whose sizes are not. Asserts both the parsed offset and a successful read of the entry's bytes.TestZip64AsymmetricPromotion_TruncatedExtra— confirmsErrFormatwhen the extra claims promotion without data.go test ./...— full suite green, includingTestZip64,TestPasswordHelloWorldAes,TestZipCrypto, etc.The hand-built fixture lives in
reader_test.gorather thantestdata/. It's a few hundred bytes assembled at test time from explicit struct fields, which is more reviewable than a binary blob and serves as a regression guard with no fixture-maintenance overhead.