Repository navigation
Conversation
…dget ZipArtifactReader decompressed every regular entry through entry.getData with no ceiling: entry.uncompressedSize was surfaced as declaredSize for inventory but never enforced, so a small compressed archive could force unbounded decompression in the reader's PassThrough stream. open() now rejects entries over MAX_ENTRY_BYTES (64 MiB) with the existing typed ArtifactReaderFailure reason "limit", matching the per-document budgets already used by KeyedArchiveReader, AppleAssetCatalogAnalysis, and InterfaceBuilderAnalysis. The rejection lands in the existing projection path where reason "limit" reports category truncated with truncated: true, and inventory observation is unchanged: oversized entries are still listed with their declared size, only extraction refuses them. zip.js 2.15 already errors when streamed output disagrees with the declared size, so enforcing the declaration at open() closes classic zip bombs before any decompression starts.
N0zoM1z0
reviewed
Oct 8, 2026
N0zoM1z0
left a comment
Collaborator
There was a problem hiding this comment.
Closing this version because the fixed 64 MiB limit rejects valid ZIP/APK/IPA/MSIX entries without an established memory regression. The current reader already awaits backpressure and aborts its producer on cancellation/consumer close. I streamed and hashed a valid 65 MiB entry (68,157,440 bytes) successfully while retaining only the existing 8 KiB classification prefix, and all seven archive integrity/safety/cancellation tests passed. A forged uncompressed-size probe was rejected by zip.js before any bytes reached the consumer. These results do not support weakening existing large-artifact usability with this cap.
10 tasks done
Owner
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
ZipArtifactReaderdecompressed every regular ZIP entry without any ceiling. The declared size was already surfaced to inventory asdeclaredSize, butopen()never enforced it, so a small compressed archive could drive unbounded decompression through the reader's internal stream and exhaust memory during extraction. This PR rejects entries over 64 MiB atopen()with the reader's existing typed failure, before any decompression starts.There is no linked issue. I did not find an open or closed issue tracking this; the nearby work is #594 (interrupt ZIP extraction under backpressure), #1013 (overlap check performance), and #847 (path constraint diagnostics), none of which add a size budget.
Problem and expected behavior
Smallest trigger: a crafted ZIP whose single file entry decompresses past 64 MiB (the fixture in this PR is a few hundred bytes on disk after compression). On the base revision,
reader.open(entry)resolves a stream andentry.getData()decompresses the full payload with only backpressure applied:The violated invariant is the resource bound on untrusted target bytes: a value the format itself declares (
uncompressedSize) should gate allocation before the work happens, not after. Expected behavior: an oversized entry refuses extraction with a typed, caller-visible error that names the limit, while inventory still lists the entry and its declared size so observation stays complete.The caller sees the existing limit projection end to end:
{ "reason": "limit", "message": "ZIP entry exceeds the 64 MiB per-entry limit: huge.bin" }ArtifactProviderpasses the reason through asArtifactOperationError, andanalysisErrorProjectionalready mapsreason: "limit"to categorytruncatedwithtruncated: true, the same path the asset-catalog and per-document decode limits use today.Change and scope
I added
MAX_ENTRY_BYTES = 64 * 1024 * 1024inZipArtifactReaderand one check inopen()after the existing directory, symlink, and encrypted-entry rejections: whenstored.uncompressedSizeexceeds the budget,open()rejects withArtifactReaderFailure("limit", ...)instead of resolving the extraction stream. The number is not invented:KeyedArchiveReader,AppleAssetCatalogAnalysis, andInterfaceBuilderAnalysisall use 64 MiB per-document budgets, andInterfaceBuilderAnalysisalready words its error as a "64 MiB per-document decode limit", so this lines the ZIP reader up with its siblings.The check enforces the declared size, which is sufficient because zip.js 2.15 already verifies streamed output against the declaration (I confirmed this by patching a fixture header to lie about its size;
getDatafails with "Invalid uncompressed size"). Classic zip bombs declare their true huge size, so refusing the declaration atopen()stops them before inflate runs. Inventory behavior is untouched by design: oversized entries are still enumerated with their realdeclaredSize, and only extraction refuses them.Intentionally not included: an aggregate budget across an archive's total extracted bytes (consumers such as extraction already apply their own totals, and a second aggregate belongs with that layer), and any change to path validation, which #847 already reports precisely.
Contract and boundary impact
src/artifacts/ZipArtifactReader.tsowns the check, and the effect starts atreader.open(), before any bytes are decompressed.inventory_artifactoutput is unchanged; extraction of a single entry over 64 MiB now fails with reasonlimit(projected as categorytruncated,truncated: true) instead of streaming an unbounded payload.zip,ipa,apk,msix, andappxformats, so all of them gain the same per-entry budget. No provider or bridge code changed, and the check is plain number comparison with no platform behavior.docs/product-catalog.json), package, or installation impact: none; no contract descriptions changed, so no catalog regeneration is part of this PR.Evidence and regression coverage
src/artifacts/ZipArtifactReader.test.tswith three cases: an over-budget entry is rejected withArtifactReaderFailurereasonlimit, an entry within the budget still extracts to the expected content, and inventory still observes an over-budget entry with its declared size.limitfailure message shown above, surfaced through the existingtruncatedcategory for limit-class errors.For evidence-bearing changes:
Validation performed
npm run typecheck— passed, 0 errors.npx vitest run src/artifacts/ZipArtifactReader.test.ts tests/boundary/filesystem/artifactZipIntegrity.test.ts --coverage.enabled=false— 2 files, 6 tests passed.npx vitest run src/artifacts tests/boundary/filesystem/artifactZipIntegrity.test.ts tests/boundary/filesystem/zipDetection.test.ts --coverage.enabled=false— 10 files, 49 tests passed, 1 skipped; no regressions in the reader, extraction, or integrity suites.AppleAssetCatalogAnalysistests fail on this base revision with and without the branch applied (reproduced with the change stashed), so they are pre-existing and unrelated.npx oxlint src/artifacts/ZipArtifactReader.ts src/artifacts/ZipArtifactReader.test.ts— 0 errors.npx oxfmt --check src/artifacts/ZipArtifactReader.ts src/artifacts/ZipArtifactReader.test.ts— clean.Compatibility, safety, and release
Review checklist
type(scope): outcome.