Repository navigation
fix(domain): avoid overflow in bounded zlib decoding - #263
Merged
Merged
Conversation
johnny4young
marked this pull request as ready for review
October 7, 2026 21:39
…imit - Clamp the output limit to zero before sizing the chunk so a negative limit can never reach UnsafeMutablePointer.allocate with a negative capacity, while Int.max still avoids the sentinel-byte overflow. - Build the empty raw DEFLATE stream by hand, cover -1, -2, and Int.min, and pin the 64 KiB boundary at 65535, 65536, and 65537 bytes.
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.
Finding
The public bounded zlib decoder computes
maxOutputBytes + 1before clamping the chunk allocation. A validInt.maxceiling therefore overflows for even a tiny compressed payload. Current share-link callers use a fixed smaller limit; this is defensive public-API correctness, not a demonstrated current-app crash.Change
Clamp the nonnegative limit before adding the sentinel byte. The buffer remains at most 64 KiB, and decompression still rejects output beyond the caller's unchanged ceiling.
Regression coverage
Three native tests cover:
Deduplication
All 12 open PRs #251–262 were inventoried, including complete changed-file lists. None changes ShareLinkCoding.swift or adds these domain tests. This main-based correction is independent of the broad app review, CLI/file safety repairs, dependency reconciliation and UI profiling/optimization candidates. No performance benefit is claimed.
Validation and limits
Source head: a70420e
Tree: e519ea71127253d2149002c9b58a9d5ebfeec9ae
Main base: bb8fea0
Ready for human review after the exact-head qualification below.
Exact-head qualification
CI 37660531515 completed successfully for unchanged head a70420e: all five jobs passed.
This qualifies this main-based correction only, not other open branches or the published app release. No merge, release or deployment.