Fix extra-field cloning ownership leak - #562
Closed
carrerasdarren-cell wants to merge 1 commit into
Closed
Conversation
Keep unchanged extra fields shared by generic dirent clones, and deep-clone them only when the extra-field API prepares an entry for mutation. This prevents attacker-sized metadata from leaking when callers rename or otherwise edit archive entries. Assisted-by: OpenAI Codex
dillof
added a commit
that referenced
this pull request
Aug 19, 2026
Member
|
Good catch, thanks. However, your fix was slightly wrong: The extra fields need to be cloned when they are first changed, even if the direntry was already cloned earlier. We've applied the correct fix. |
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
Impact
Commit
cbad2bamade_zip_dirent_clone()deep-copy every extra field, but_zip_dirent_finalize()deliberately frees extra fields only whenZIP_DIRENT_EXTRA_FIELDis marked changed. As a result, ordinary operationssuch as renaming an entry leak the copied, archive-controlled extra fields when
the archive is discarded.
In a long-lived archive normalization or repackaging service, repeated hostile
archives can therefore grow process memory until exhaustion. The input does not
need to be malformed.
A local harness used a 1.0 MiB ZIP with 16 maximum-sized central extra fields,
then opened, renamed, and discarded all entries 100 times:
main: 107.8 MiB peak footprintApple's
leakstool also traced the leaked allocations directly through_zip_dirent_clone()and_zip_extra_fields_clone().Validation
git diff --check: clean