fix: don't pre-allocate the declared size in the legacy decoders #991
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
youdie006
The three legacy decoders hand an entry's declared uncompressed size straight to
Vec::reserve, so a 200-byte archive that declares0xFFFF_FFFF_FFFF_FFFFbytes panics out of the public read API:Reached by
ZipArchive::by_index(0)thenread_to_end. TheStoredsibling on an otherwise identical archive returnsErr("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 thereserveis 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 fromgit show HEAD:).<details>
<summary>Verification</summary>
Base
75eec5b.| row | new test file |
|---|---|
| base | 4 ran, 3 failed (
capacity overflowin Shrink, Reduce, Implode;Storedpasses) || this PR | 4 ran, 4 passed |
| revert
shrink.rs:234alone | 4 ran, 1 failed (the Shrink case) || revert
reduce.rs:107alone | 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
Storedcase 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 owntests/legacy_zip.rsround-trips ofshrink.zip,reduce.zipandimplode.zipstill pass.cargo clippy --no-default-features --features legacy-zip --lib -- -D warningsclean;cargo doc --no-depsclean;cargo fmt --check --allclean.cargo clippy --all-targets -- -D warningsfails, but identically with my changes and on an unmodified tree:tests/data_descriptor.rs:27tripsclippy::bool_assert_comparisonon 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 isusize::minon ausize.</details>
Possibly relevant to why this lasted:
fuzz/readdrives exactly this path,by_indexplusio::copy, butfuzz/Cargo.tomlpinszipwithdefault-features = falseand only azip-defaultknob, andlegacy-zipis not indefault. The fuzzer has never compiled these decoders.Two things I did not do.
MAX_PREALLOC = 1 << 20is a guess at the right ceiling; deriving it from the compressed length would be just as easy if you prefer that. AndImplodeDecoder::readandShrinkDecoder::readeach 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.