← Back to Pull requests

fix: don't pre-allocate the declared size in the legacy decoders #991

Closed
unknown closed this pull request without merging on Sep 16, 2026 03:34 UTC
View on GitHub
unknown unknown commented on Sep 15, 2026 01:03 UTC
Author

The three legacy decoders hand an entry's declared uncompressed size straight to Vec::reserve, so a 200-byte archive that declares 0xFFFF_FFFF_FFFF_FFFF bytes panics out of the public read API:

thread 'main' panicked at library/alloc/src/raw_vec/mod.rs:28:5
capacity overflow

Reached by ZipArchive::by_index(0) then read_to_end. The Stored sibling on an otherwise identical archive returns Err("Invalid checksum"), which is what the template's "all the crate's methods remain panic-free" line asks for.

Clamping rather than rejecting, because the template also says ZIP bombs are not filtered: the decode loops (while dst.len() < uncomp_len) append and grow on their own, so the reserve is only a hint and a large legitimate entry still decodes.

Five sites, all with the same shape: shrink.rs:234, shrink.rs:347, reduce.rs:107, implode.rs:97, implode.rs:214 (line numbers from git show HEAD:).

<details>
<summary>Verification</summary>

Base 75eec5b.

| row | new test file |
|---|---|
| base | 4 ran, 3 failed (capacity overflow in Shrink, Reduce, Implode; Stored passes) |
| this PR | 4 ran, 4 passed |
| revert shrink.rs:234 alone | 4 ran, 1 failed (the Shrink case) |
| revert reduce.rs:107 alone | 4 ran, 1 failed (the Reduce case) |
| MAX_PREALLOC = usize::MAX | 4 ran, 3 failed |

Each single-site revert is caught by its own decoder's case, so no site is redundant. The Stored case passes in every row, which is what makes the other three a real divergence rather than a broken harness.

cargo test --no-default-features --features legacy-zip: 28 result blocks, 0 failures, and the repo's own tests/legacy_zip.rs round-trips of shrink.zip, reduce.zip and implode.zip still pass. cargo clippy --no-default-features --features legacy-zip --lib -- -D warnings clean; cargo doc --no-deps clean; cargo fmt --check --all clean.

cargo clippy --all-targets -- -D warnings fails, but identically with my changes and on an unmodified tree: tests/data_descriptor.rs:27 trips clippy::bool_assert_comparison on rustc 1.97.0. Not from this change.

Not run here: the Windows and macOS legs, the MSRV 1.88 leg, and --all-features. The change is usize::min on a usize.

</details>

Possibly relevant to why this lasted: fuzz/read drives exactly this path, by_index plus io::copy, but fuzz/Cargo.toml pins zip with default-features = false and only a zip-default knob, and legacy-zip is not in default. The fuzzer has never compiled these decoders.

Two things I did not do. MAX_PREALLOC = 1 << 20 is a guess at the right ceiling; deriving it from the compressed length would be just as easy if you prefer that. And ImplodeDecoder::read and ShrinkDecoder::read each reserve and then call a helper that reserves the same value again, which looks redundant but is a separate change.

---

Disclosure: written with the help of Claude (an AI assistant). Every number above is from runs on my machine.

Diff: 375 lines (+281 / -94) across 4 files Reviewer: youdie006 Review duration: 1590m
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.43) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 375 lines diff across 4 files
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.355
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #991"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 42.9% (MEDIUM) · Higher = larger blast radius
42.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 18.5% · Safe to merge
18.5%
Repository