Repository navigation
Fix corrupted zip when round-tripping entries with a data descriptor (#555) - #564
Merged
cthackers merged 1 commit intoJun 29, 2026
Merged
Conversation
…thackers#555) Entries whose general-purpose bit flag has bit 3 (0x08, "data descriptor") set store their crc-32 and sizes in a trailing descriptor, not in the local header. On write, adm-zip rebuilds full local headers with the real crc/sizes but kept bit 3 set while emitting no trailing descriptor. The result was a zip that adm-zip itself (and strict unzip implementations) could not read back, failing with "ADM-ZIP: No descriptor present". Since compressToBuffer always knows the crc/sizes at write time and never emits a descriptor, clear bit 3 in both the local and central header serialization. The in-memory flags are left untouched; only the emitted bytes are normalized. Adds test/issue_555 with a sample.docx whose entries use data descriptors, reproducing the reported read -> write -> read failure.
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 #555.
Reading a zip and writing it back out could produce a file that adm-zip itself (and strict
unzipimplementations) refused to read, failing withADM-ZIP: No descriptor present.It affects entries whose general-purpose bit flag has bit 3 (
0x08, "data descriptor") set — the way MS Office.docx, .NET packaging and streaming archivers write their files. For those entries the real crc-32 and sizes livein a trailing data descriptor after the compressed data, and the local header holds zeros.
On write, adm-zip rebuilds a full local header with the real crc/sizes, but it kept bit 3 set while emitting no trailing descriptor. The output then claims "a descriptor follows" when none does; on the next read
crc32OK()looks for it right after the data, hits the next header signature instead, and throws.
Fix
compressToBufferalways knows the crc/sizes at write time and never emits a descriptor, so bit 3 must not be set on output. Clear it in both the local and central header serialization (headers/entryHeader.js):The in-memory flags are left untouched — only the emitted bytes are normalized, so reading an entry's metadata after parsing is unchanged.
Test
Adds
test/issue_555with asample.docxwhose entries use data descriptors. The test runs the exact flow from the issue (writeZipPromise → toBufferPromise → getEntries() → getData()). It throws No descriptor present without the fix and passes with it. Full suite: 92 passing.Notes
A .docx only triggers this if its producer actually used data descriptors —
some do, some don't, which is why the report looked intermittent.