Skip to content

fix(tarball): bound gzip size hints - #12993

Merged
zkochan merged 6 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/pacquet-unpacked-size-hint
Jul 17, 2026
Merged

zkochan merged 6 commits into
pnpm:mainfrom
YESHYUNGSEOK:fix/pacquet-unpacked-size-hint

Conversation

@YESHYUNGSEOK

@YESHYUNGSEOK YESHYUNGSEOK commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Registry metadata can supply an arbitrary dist.unpackedSize, and pacquet passed that value directly to zune-inflate as an eager output-buffer allocation hint. zune-inflate reserves the hint as an infallible zero-filled vec![0; hint], so an arbitrary registry figure aborts the process rather than failing gracefully — multiplied across concurrent post-download tasks.

  • Clamp gzip hints to the tarball module's existing 64 MiB untrusted-preallocation ceiling, now shared with the ZIP entry reservation that already bounded against the same figure.
  • Bound the eager reservation only, never the output: zune-inflate grows its buffer on demand, so an archive larger than the ceiling still decodes in full.
  • Cover the boundary scalars, plus the wiring that routes the registry figure through the bound.

The TypeScript CLI does not use dist.unpackedSize as a decompressor allocation hint, so no TypeScript-side change is needed.

Why clamp rather than omit

Omitting an oversized hint also bounds the allocation, but discards the pre-sizing for honest large packages, which then grow from zune-inflate's 37 KB default in 4 KiB steps. Decompressing an 80 MiB package (release, best-of-3):

hint strategy time
omitted 72.3 ms
unbounded (pre-fix) 17.7 ms
clamped to 64 MiB 11.4 ms

Clamping is safe from a memory-consumption perspective: vec![0; 64 MiB] is lazily backed, so pages the decoder never writes never become resident. With 20 concurrent tiny packages each claiming usize::MAX (matching post_download_semaphore's num_cpus * 2), every buffer held alive at once:

20 lying pkgs (usize::MAX hint) held: RSS +0.7 MiB (eager would be +1280 MiB)

Clamping therefore keeps the change to the smallest correct one — behavior differs from the pre-fix code only for figures above the ceiling — and matches the sibling ZIP entry reservation, which has always clamped against this same bound.

Verified with:

  • cargo test --locked -p pacquet-tarball --lib (74 passed)
  • An 80 MiB archive round-tripped through decompress_gzip with a truthful over-ceiling hint, length and content asserted
  • cargo fmt --all --check
  • cargo clippy --locked -p pacquet-tarball --all-targets -- --deny warnings
  • RUSTDOCFLAGS=-D warnings cargo doc --locked -p pacquet-tarball --no-deps
  • typos pnpm/crates/tarball .changeset/bound-pacquet-gzip-hints.md
  • The repository pre-push hook, including TypeScript compile/lint, workspace Rust clippy/rustdoc, and Rust spell checking

Squash Commit Body

Registry-provided dist.unpackedSize was forwarded unbounded to zune-inflate as an eager output-buffer allocation hint. zune-inflate reserves it as an infallible zero-filled `vec![0; hint]`, so an arbitrary registry figure could abort the process instead of failing gracefully, multiplied across concurrent post-download tasks.

Clamp the hint to the tarball module's existing 64 MiB untrusted-preallocation ceiling, now shared with the zip entry reservation that already bounded against the same figure. The ceiling bounds the eager reservation only, never the output: zune-inflate grows its buffer on demand, so an archive larger than the ceiling still decodes in full.

Clamping preserves the pre-sizing the hint exists for. Omitting an oversized hint instead would leave an honest large package growing from the decoder's small default, measured ~6x slower on an 80 MiB archive. A clamped reservation is lazily backed, so a package that overstates its size holds address space rather than resident memory: 20 concurrent tiny packages each claiming usize::MAX hold +0.7 MiB RSS.

Add boundary coverage for absent, ordinary, exact-limit, over-limit, and maximum-size hints, plus a test that decompress_gzip routes the registry figure through the bound rather than forwarding it raw.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Codex, GPT-5).
Description and squash body revised by an agent (Claude Code, claude-opus-4-8) after the clamp change.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • Capped registry-provided gzip preallocation hints to 64 MiB to prevent excessive eager memory allocation.
    • Clamped ZIP extraction preallocation so oversized or untrusted advertised entry sizes can’t drive large upfront reservations.
  • Tests
    • Added unit tests covering gzip hint bounding and ensuring decompression works when given oversized unpacked-size hints.
  • Release
    • Prepared a patch release for the pacquet package.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@zkochan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 16 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a31835f-fac2-4cc3-930d-0fbb8edafffe

📥 Commits

Reviewing files that changed from the base of the PR and between 4b0f5a2 and 0c58e3d.

📒 Files selected for processing (2)
  • pnpm/crates/tarball/src/lib.rs
  • pnpm/crates/tarball/src/tests.rs
📝 Walkthrough

Walkthrough

Pacquet caps untrusted gzip and zip preallocation hints at 64 MiB. Gzip hints are filtered before configuring decompression, zip entry sizes are clamped, tests cover boundary behavior, and a patch changeset documents the update.

Changes

Pacquet preallocation bounds

Layer / File(s) Summary
Bound archive preallocation hints
pnpm/crates/tarball/src/lib.rs, pnpm/crates/tarball/src/tests.rs, .changeset/bound-pacquet-gzip-hints.md
A shared 64 MiB limit bounds gzip and zip preallocation hints; gzip boundary cases and oversized-hint decompression are tested, and the patch changeset documents the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: product: pacquet

Suggested reviewers: zkochan, zkochan

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Jul 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.45%. Comparing base (e7138af) to head (0c58e3d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12993      +/-   ##
==========================================
- Coverage   85.45%   85.45%   -0.01%     
==========================================
  Files         501      501              
  Lines       80654    80657       +3     
==========================================
+ Hits        68924    68926       +2     
- Misses      11730    11731       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 4b0f5a2db1bf

Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD.

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.657 ± 0.193 2.445 2.921 1.63 ± 0.19
pacquet@main 2.590 ± 0.157 2.447 2.833 1.59 ± 0.17
pnpr@HEAD 1.631 ± 0.143 1.404 1.821 1.00
pnpr@main 1.634 ± 0.171 1.411 1.940 1.00 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.65739056144,
      "stddev": 0.19326845903938733,
      "median": 2.63905232854,
      "user": 2.3957043199999997,
      "system": 1.8346377399999998,
      "min": 2.4449414730399996,
      "max": 2.92084054904,
      "times": [
        2.69044367604,
        2.92084054904,
        2.9030476090399997,
        2.8980534530399997,
        2.49336641804,
        2.47733580304,
        2.58766098104,
        2.46545700104,
        2.69275865104,
        2.4449414730399996
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.59012812644,
      "stddev": 0.1565464804471143,
      "median": 2.52465565704,
      "user": 2.28990192,
      "system": 1.7871142400000004,
      "min": 2.4474786210399997,
      "max": 2.8334004340399996,
      "times": [
        2.4601108410399997,
        2.6023267620399997,
        2.5091326820399997,
        2.77021214604,
        2.8334004340399996,
        2.46748516104,
        2.4575206650399997,
        2.4474786210399997,
        2.81343532004,
        2.54017863204
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.63111444834,
      "stddev": 0.1430856327216798,
      "median": 1.64561331654,
      "user": 1.61473482,
      "system": 1.5215756399999996,
      "min": 1.40446487804,
      "max": 1.8210823200400001,
      "times": [
        1.52765914304,
        1.76049049104,
        1.66441084404,
        1.40446487804,
        1.8210823200400001,
        1.4183341630400002,
        1.73773695904,
        1.62681578904,
        1.73723005604,
        1.6129198400400002
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.6339826541399998,
      "stddev": 0.17121594174723997,
      "median": 1.64630946754,
      "user": 1.6678167199999998,
      "system": 1.5754921400000002,
      "min": 1.41130198004,
      "max": 1.94026168504,
      "times": [
        1.67596788904,
        1.42866249504,
        1.7630242720400002,
        1.41130198004,
        1.57524953304,
        1.44990889704,
        1.74176719004,
        1.73703155404,
        1.61665104604,
        1.94026168504
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 311.5 ± 37.7 267.8 393.2 1.00
pacquet@main 356.1 ± 13.7 342.3 385.0 1.14 ± 0.15
pnpr@HEAD 360.5 ± 13.7 342.2 392.0 1.16 ± 0.15
pnpr@main 344.2 ± 12.3 331.4 365.2 1.11 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.31145705100000004,
      "stddev": 0.037655765460563616,
      "median": 0.29954296750000003,
      "user": 0.26784232,
      "system": 0.60229514,
      "min": 0.26777122400000003,
      "max": 0.39317340500000003,
      "times": [
        0.32232433200000005,
        0.29644486500000006,
        0.28527989800000003,
        0.30226445,
        0.28418772500000006,
        0.26777122400000003,
        0.29682148500000005,
        0.30903449800000005,
        0.35726862800000003,
        0.39317340500000003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.35605429090000007,
      "stddev": 0.0136564562503561,
      "median": 0.35218526150000007,
      "user": 0.30461511999999996,
      "system": 0.68203394,
      "min": 0.34234915800000004,
      "max": 0.38496822,
      "times": [
        0.34404496300000004,
        0.35480864500000003,
        0.35731777300000006,
        0.34234915800000004,
        0.35284206900000004,
        0.37499772600000003,
        0.34623440000000005,
        0.35152845400000005,
        0.38496822,
        0.35145150100000005
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.36054417550000006,
      "stddev": 0.013723071816906893,
      "median": 0.35987195450000004,
      "user": 0.30039472,
      "system": 0.6692095399999999,
      "min": 0.34222162300000003,
      "max": 0.39197832600000004,
      "times": [
        0.36014051900000005,
        0.366302047,
        0.369703822,
        0.34926926900000005,
        0.35287884500000005,
        0.35236421,
        0.39197832600000004,
        0.35960339,
        0.34222162300000003,
        0.360979704
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.34422062150000005,
      "stddev": 0.012335081321216409,
      "median": 0.34420309200000004,
      "user": 0.28757341999999997,
      "system": 0.64493434,
      "min": 0.33139603300000003,
      "max": 0.36517076500000006,
      "times": [
        0.35326499100000003,
        0.36098962100000004,
        0.34448554800000003,
        0.34392063600000006,
        0.33197658100000005,
        0.36517076500000006,
        0.33219838100000004,
        0.34496766500000003,
        0.333835994,
        0.33139603300000003
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.897 ± 0.043 2.809 2.966 1.78 ± 0.15
pacquet@main 2.847 ± 0.060 2.784 2.952 1.75 ± 0.15
pnpr@HEAD 1.624 ± 0.138 1.483 1.886 1.00
pnpr@main 1.699 ± 0.121 1.491 1.852 1.05 ± 0.12
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.8970082435400006,
      "stddev": 0.04279188513088855,
      "median": 2.90350565024,
      "user": 2.4444551,
      "system": 1.8223485999999998,
      "min": 2.80930282674,
      "max": 2.9660474007400004,
      "times": [
        2.80930282674,
        2.9660474007400004,
        2.9228015597400003,
        2.89670568174,
        2.87658757374,
        2.8766965147400003,
        2.86609826774,
        2.9103056187400003,
        2.92856844274,
        2.9169685487400003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.8471213850400003,
      "stddev": 0.060281885720403654,
      "median": 2.8342537392400002,
      "user": 2.3079247,
      "system": 1.6686738,
      "min": 2.7836878727400003,
      "max": 2.95184578274,
      "times": [
        2.82926037474,
        2.84543301274,
        2.83924710374,
        2.8693780607400003,
        2.7836878727400003,
        2.81833589374,
        2.78518343574,
        2.80134776074,
        2.95184578274,
        2.9474945527400003
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.6237310741399997,
      "stddev": 0.13818841120349495,
      "median": 1.58720417974,
      "user": 1.7100009,
      "system": 1.6140923,
      "min": 1.4833449657400002,
      "max": 1.8859091877400003,
      "times": [
        1.54082988674,
        1.8372606527400002,
        1.51787537574,
        1.6529700517400001,
        1.8859091877400003,
        1.55923981274,
        1.61516854674,
        1.64083848774,
        1.50387377374,
        1.4833449657400002
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.6986828253400001,
      "stddev": 0.12096439537901121,
      "median": 1.69447215974,
      "user": 1.5767601,
      "system": 1.4813449,
      "min": 1.49113188874,
      "max": 1.8517738977400002,
      "times": [
        1.49113188874,
        1.84824769374,
        1.6530139787400002,
        1.7565700907400001,
        1.6428846537400001,
        1.55086448874,
        1.72099293374,
        1.8033972417400002,
        1.6679513857400001,
        1.8517738977400002
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 619.3 ± 46.3 560.5 707.9 2.00 ± 0.18
pacquet@main 571.2 ± 32.4 543.6 655.0 1.84 ± 0.14
pnpr@HEAD 315.6 ± 18.8 288.6 345.0 1.02 ± 0.08
pnpr@main 310.2 ± 16.6 288.4 342.1 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6192824396400001,
      "stddev": 0.04629313909255523,
      "median": 0.6229767096400001,
      "user": 0.8037636799999998,
      "system": 0.7408885399999997,
      "min": 0.56048872864,
      "max": 0.70788732164,
      "times": [
        0.56700699664,
        0.58611606064,
        0.61901202664,
        0.70788732164,
        0.6393703886400001,
        0.62694139264,
        0.64203092964,
        0.66168964264,
        0.56048872864,
        0.58228090864
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.57117032184,
      "stddev": 0.032362030163673124,
      "median": 0.5629271091400001,
      "user": 0.7238951799999999,
      "system": 0.71758494,
      "min": 0.54364161764,
      "max": 0.65495898764,
      "times": [
        0.58740975864,
        0.55109517464,
        0.55874271264,
        0.5661604006400001,
        0.57577880964,
        0.54586854564,
        0.54364161764,
        0.55969381764,
        0.56835339364,
        0.65495898764
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.31557349043999994,
      "stddev": 0.018823788591652586,
      "median": 0.31567765414000004,
      "user": 0.21056017999999996,
      "system": 0.54590924,
      "min": 0.28857818264,
      "max": 0.34496386264,
      "times": [
        0.34496386264,
        0.32219624464,
        0.33415917564,
        0.29695051664,
        0.31691530264,
        0.29974594464,
        0.28857818264,
        0.31444000564,
        0.30179402964,
        0.33599163964
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.3102248663399999,
      "stddev": 0.016582161034069072,
      "median": 0.30795546314,
      "user": 0.19413507999999996,
      "system": 0.5398469399999999,
      "min": 0.28841465364,
      "max": 0.34213715964,
      "times": [
        0.34213715964,
        0.33131449664,
        0.31580039864,
        0.30776363564,
        0.30814729064,
        0.29895118364,
        0.30102865964,
        0.31468004564,
        0.28841465364,
        0.29401113964
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.929 ± 0.045 1.874 2.016 6.64 ± 0.35
pacquet@main 1.892 ± 0.046 1.822 1.974 6.52 ± 0.35
pnpr@HEAD 0.290 ± 0.014 0.272 0.314 1.00
pnpr@main 0.305 ± 0.015 0.280 0.321 1.05 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.9286401799,
      "stddev": 0.04532661533811079,
      "median": 1.9257021572,
      "user": 1.06966976,
      "system": 0.8727502399999999,
      "min": 1.8742246827,
      "max": 2.0161817857,
      "times": [
        1.9845043437000003,
        1.9365270817,
        1.8868664527,
        1.9429473297000002,
        1.9348032287,
        1.9166010857,
        1.9131816447,
        1.8805641637000001,
        1.8742246827,
        2.0161817857
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.8918243022000003,
      "stddev": 0.04559765612402977,
      "median": 1.8815538172000001,
      "user": 1.0258950599999999,
      "system": 0.8484582399999999,
      "min": 1.8220881847000001,
      "max": 1.9740174977000002,
      "times": [
        1.9468696277000002,
        1.9740174977000002,
        1.9265476967000001,
        1.8822653347,
        1.8976365417,
        1.8571095507000002,
        1.8220881847000001,
        1.8808422997000003,
        1.8680699947000001,
        1.8627962937000002
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.290298283,
      "stddev": 0.013775612840605692,
      "median": 0.28584151570000005,
      "user": 0.16644145999999999,
      "system": 0.5199101399999999,
      "min": 0.27210727370000004,
      "max": 0.31403943170000004,
      "times": [
        0.28129954570000004,
        0.2894467047,
        0.27210727370000004,
        0.3020386097,
        0.30965979870000004,
        0.28091566570000004,
        0.2827720067,
        0.28179276870000003,
        0.31403943170000004,
        0.2889110247
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.30543456179999995,
      "stddev": 0.01520131631038301,
      "median": 0.3106384057,
      "user": 0.20054165999999998,
      "system": 0.52912924,
      "min": 0.28005967470000004,
      "max": 0.3206407337,
      "times": [
        0.28005967470000004,
        0.2999075037,
        0.3147216667,
        0.3086533167,
        0.3126234947,
        0.32046350770000004,
        0.3206407337,
        0.32036938670000004,
        0.2886919157,
        0.2882144177
      ]
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 352.5 ± 30.2 327.6 412.3 4.05 ± 0.38
pacquet@main 386.2 ± 16.0 357.5 412.2 4.43 ± 0.25
pnpr@HEAD 87.1 ± 3.4 82.7 102.3 1.00
pnpr@main 91.1 ± 4.1 84.7 101.5 1.05 ± 0.06
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.35251358476,
      "stddev": 0.030219305740509406,
      "median": 0.34258810936,
      "user": 0.33590887999999997,
      "system": 0.08349700000000002,
      "min": 0.32757882386000003,
      "max": 0.41230227186,
      "times": [
        0.35046281786,
        0.32757882386000003,
        0.40398691386,
        0.41230227186,
        0.34549678186,
        0.33967943686,
        0.34552465186000003,
        0.33275673686,
        0.33536310886000004,
        0.33198430386
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.38615761996,
      "stddev": 0.015979763358612786,
      "median": 0.38516012536,
      "user": 0.36741008,
      "system": 0.097607,
      "min": 0.35751350786,
      "max": 0.41219951586000003,
      "times": [
        0.35751350786,
        0.39591496186,
        0.38516776386,
        0.38397381486000004,
        0.36865177186000003,
        0.37889165686000004,
        0.40415376786,
        0.41219951586000003,
        0.38995695186,
        0.38515248686000003
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.08713043882969695,
      "stddev": 0.003397194852585654,
      "median": 0.08650698386000001,
      "user": 0.01830130121212121,
      "system": 0.012586803030303026,
      "min": 0.08272759886000002,
      "max": 0.10232726986000001,
      "times": [
        0.08509635686000001,
        0.08650698386000001,
        0.08652619586000002,
        0.08742821986000002,
        0.08532100286000001,
        0.08315959986000002,
        0.08838189086,
        0.08455760386000001,
        0.08524421186000002,
        0.08796593486000001,
        0.08878542086,
        0.08628673786,
        0.08572355186000001,
        0.08687182286000002,
        0.08272759886000002,
        0.08591173686,
        0.09032899486000001,
        0.09025852286000001,
        0.08506846786000001,
        0.08884734386000001,
        0.08520492686000002,
        0.08904183486000002,
        0.08291990986000002,
        0.08603692686000002,
        0.08683315386000001,
        0.08525632986000001,
        0.08543921386000002,
        0.09001161186000001,
        0.08700469186000001,
        0.08829201786000002,
        0.08946938786000001,
        0.08646900686000002,
        0.10232726986000001
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.09108202599333333,
      "stddev": 0.004089490806947493,
      "median": 0.09003404536000001,
      "user": 0.01940421333333333,
      "system": 0.01504715,
      "min": 0.08465973386000002,
      "max": 0.10148767386000002,
      "times": [
        0.09038175086000001,
        0.09049870886000001,
        0.09099249186000001,
        0.09675302386000001,
        0.09490320786,
        0.08862326886,
        0.09346033386000001,
        0.09396047286,
        0.08780898486000001,
        0.08642372586000001,
        0.08465973386000002,
        0.08693388586,
        0.10148767386000002,
        0.08865498086000001,
        0.08775720286000001,
        0.09778363186000001,
        0.09266323186000001,
        0.08658073886,
        0.08798925886000002,
        0.08787616686000001,
        0.09611517986000001,
        0.09466005786000001,
        0.09486655586000001,
        0.08694239586000001,
        0.08704426886000001,
        0.08968633986,
        0.09461790686000002,
        0.08944110386000001,
        0.09373799686,
        0.08915649886000002
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.694 ± 0.144 4.519 4.933 1.31 ± 0.05
pacquet@main 4.728 ± 0.215 4.490 5.090 1.32 ± 0.07
pnpr@HEAD 3.581 ± 0.088 3.479 3.758 1.00
pnpr@main 3.725 ± 0.143 3.589 3.990 1.04 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.69351045676,
      "stddev": 0.1444423508069782,
      "median": 4.66506967506,
      "user": 2.4205289,
      "system": 1.8231519799999998,
      "min": 4.519257480059999,
      "max": 4.93325840106,
      "times": [
        4.82312229206,
        4.519257480059999,
        4.93325840106,
        4.624556968059999,
        4.81659558106,
        4.55283488806,
        4.53890646506,
        4.80747624906,
        4.70558238206,
        4.6135138610599995
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.728085576659999,
      "stddev": 0.21476393104465027,
      "median": 4.654477571059999,
      "user": 2.5789649,
      "system": 1.93682008,
      "min": 4.48968599806,
      "max": 5.08993308306,
      "times": [
        5.07116035706,
        4.62775807006,
        4.81875995106,
        4.59145715706,
        5.08993308306,
        4.61072079506,
        4.7993392970599995,
        4.50084398606,
        4.48968599806,
        4.68119707206
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.5811489337599993,
      "stddev": 0.08816031796032221,
      "median": 3.5491528345599996,
      "user": 1.6814489,
      "system": 1.52637218,
      "min": 3.47913501706,
      "max": 3.75789762506,
      "times": [
        3.75789762506,
        3.47913501706,
        3.5389355270599996,
        3.60187637806,
        3.5461892950599996,
        3.5521163740599997,
        3.50982495806,
        3.5056666970599997,
        3.6803070080599998,
        3.63954045806
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.7253112439600002,
      "stddev": 0.14261204498953264,
      "median": 3.68734963506,
      "user": 2.0731687,
      "system": 1.9062899799999997,
      "min": 3.58872830906,
      "max": 3.99048952706,
      "times": [
        3.65654353606,
        3.58872830906,
        3.7244285800599997,
        3.59047002706,
        3.6336585430599997,
        3.69822932206,
        3.99048952706,
        3.67646994806,
        3.72457499706,
        3.9695196500599996
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12993
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,897.01 ms
(-6.61%)Baseline: 3,101.93 ms
3,722.32 ms
(77.83%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,928.64 ms
(-12.06%)Baseline: 2,193.20 ms
2,631.84 ms
(73.28%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
619.28 ms
(-24.80%)Baseline: 823.54 ms
988.25 ms
(62.66%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
352.51 ms
(-22.38%)Baseline: 454.16 ms
544.99 ms
(64.68%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,657.39 ms
(-6.49%)Baseline: 2,841.86 ms
3,410.23 ms
(77.92%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,693.51 ms
(-10.11%)Baseline: 5,221.50 ms
6,265.80 ms
(74.91%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
311.46 ms
(-6.81%)Baseline: 334.22 ms
401.06 ms
(77.66%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12993
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,623.73 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
290.30 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
315.57 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
87.13 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,631.11 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,581.15 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
360.54 ms
🐰 View full continuous benchmarking report in Bencher

@YESHYUNGSEOK
YESHYUNGSEOK force-pushed the fix/pacquet-unpacked-size-hint branch from 243063a to a1541d0 Compare July 15, 2026 23:59
@YESHYUNGSEOK
YESHYUNGSEOK marked this pull request as ready for review July 16, 2026 01:35
@YESHYUNGSEOK
YESHYUNGSEOK requested a review from zkochan as a code owner July 16, 2026 01:35
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@greptile-apps

greptile-apps Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The security fix is structurally sound — no attacker-controlled value can drive an arbitrarily large eager allocation. One aspect needs explicit resolution before merging: the new gzip helper clamps oversized hints to 64 MiB, while the PR description and squash commit body claim they are omitted (returning no hint). Either the code should be updated to filter rather than clamp, or the description/tests should be updated to reflect clamping.

The core security property is achieved, and the codebase is internally consistent (code and tests agree on clamping). However, the squash commit body says "omitted rather than clamped," which would be a permanent factual error in git history. Resolving whether the intended behavior is clamp or omit is the one outstanding question before this is ready to merge.

pnpm/crates/tarball/src/lib.rs — the bounded_gzip_size_hint function and its description need to agree on whether oversized hints are clamped or omitted.

Reviews (5): Last reviewed commit: "docs(tarball): trim preallocation commen..." | Re-trigger Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/bound-pacquet-gzip-hints.md:
- Line 5: Update the changeset description to document the 64 MiB limit for both
registry-provided gzip preallocation hints and untrusted ZIP entry size hints,
preserving the existing scope and release-note context.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3f26a6fb-639f-4152-b118-0456e2a04a2c

📥 Commits

Reviewing files that changed from the base of the PR and between fb4639f and a1541d0.

📒 Files selected for processing (3)
  • .changeset/bound-pacquet-gzip-hints.md
  • pnpm/crates/tarball/src/lib.rs
  • pnpm/crates/tarball/src/tests.rs

Comment thread .changeset/bound-pacquet-gzip-hints.md Resolved
@zkochan
zkochan force-pushed the fix/pacquet-unpacked-size-hint branch from a1541d0 to f2406a7 Compare July 17, 2026 11:56
@qodo-code-review

qodo-code-review Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (1) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Remediation recommended

1. Oversized hint forces 64MiB 🐞 Bug ⛨ Security ⭐ New
Description
bounded_gzip_size_hint clamps attacker-controlled dist.unpackedSize to 64 MiB and decompress_gzip
forwards it to zune-inflate’s size hint, which this module documents as an infallible zero-filled
Vec allocation. With up to num_cpus*2 post-download tasks in flight, a malicious registry/package
set can still induce large aggregate eager allocations and potentially OOM/abort under memory
pressure.
Code

pnpm/crates/tarball/src/lib.rs[476]

+    unpacked_size.map(|size| size.min(MAX_UNTRUSTED_PREALLOC_BYTES))
Evidence
The code explicitly treats dist.unpackedSize as attacker-controlled and notes concurrency; it also
documents that the gzip size hint becomes a zero-filled allocation, and the helper/test confirm that
oversized values become the 64 MiB hint rather than being omitted.

pnpm/crates/tarball/src/lib.rs[32-63]
pnpm/crates/tarball/src/lib.rs[471-490]
pnpm/crates/tarball/src/tests.rs[32-45]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`bounded_gzip_size_hint` currently clamps oversized, untrusted `dist.unpackedSize` values to `MAX_UNTRUSTED_PREALLOC_BYTES`. Because `decompress_gzip` forwards that value into `set_size_hint`, oversized metadata can still force an eager 64 MiB allocation per concurrent task.

## Issue Context
This is a residual resource-exhaustion vector: it’s bounded (improves over unbounded allocation), but still attacker-triggerable and multiplied by `post_download_semaphore()` concurrency.

## Fix Focus Areas
- pnpm/crates/tarball/src/lib.rs[471-477]
- pnpm/crates/tarball/src/tests.rs[40-44]

## Suggested change
- Change `bounded_gzip_size_hint` to only return `Some(size)` when `size <= MAX_UNTRUSTED_PREALLOC_BYTES`; otherwise return `None` (omit the hint).
- Update the doc comment near `MAX_UNTRUSTED_PREALLOC_BYTES` if it no longer applies to the gzip path.
- Update the boundary test expectations accordingly (oversized inputs should map to `None`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset .changeset/bound-pacquet-gzip-hints.md lists only pacquet and omits a pnpm
bump entry, which the compliance checklist requires for changesets. If pnpm is intended to track
this fix via changesets, this omission can prevent the correct release metadata from being recorded.
Code

.changeset/bound-pacquet-gzip-hints.md[R1-3]

+---
+"pacquet": patch
+---
Evidence
The compliance checklist requires each changeset to include a pnpm entry with a valid bump type.
The added changeset front-matter contains only pacquet, so it does not meet that requirement.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/bound-pacquet-gzip-hints.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The newly added changeset does not include a `pnpm` package bump entry, which is required by the compliance checklist.

## Issue Context
The changeset currently declares only `"pacquet": patch`. Per the checklist, changeset front-matter must also explicitly declare a `pnpm` bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/bound-pacquet-gzip-hints.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Gzip test allocates 64MiB 🐞 Bug ➹ Performance ⭐ New
Description
The test decompress_gzip_bounds_oversized_unpacked_size passes usize::MAX, which the current clamp
turns into a 64 MiB size hint; per the module docs this triggers an eager zero-filled allocation
during the unit test. This makes the test suite heavier than necessary and can destabilize runs on
memory-constrained CI.
Code

pnpm/crates/tarball/src/tests.rs[53]

+fn decompress_gzip_bounds_oversized_unpacked_size() {
Evidence
The test passes usize::MAX into decompress_gzip, and decompress_gzip uses the bounded hint to
call set_size_hint; the helper clamps oversized hints to the 64 MiB ceiling, and the docs state
this hint becomes a zero-filled allocation.

pnpm/crates/tarball/src/tests.rs[47-62]
pnpm/crates/tarball/src/lib.rs[471-486]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`decompress_gzip_bounds_oversized_unpacked_size` likely causes a ~64 MiB eager allocation because it passes `usize::MAX`, which is clamped to `MAX_UNTRUSTED_PREALLOC_BYTES` and then forwarded into `set_size_hint`.

## Issue Context
This is test-only overhead but can slow CI and increase peak memory when tests run in parallel.

## Fix Focus Areas
- pnpm/crates/tarball/src/tests.rs[53-53]

## Suggested change
- If you implement the production change to *omit* oversized hints, update this test to pass `Some(MAX_UNTRUSTED_PREALLOC_BYTES + 1)` and keep asserting decompression succeeds (no large allocation).
- If production behavior remains clamping, consider removing this end-to-end test (the clamping behavior is already covered by `gzip_size_hint_enforces_untrusted_preallocation_limit`) or restructure it to avoid passing a value that triggers the maximum reserved buffer.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Previous review results

Review updated until commit 0c58e3d

Results up to commit f2406a7


🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset .changeset/bound-pacquet-gzip-hints.md lists only pacquet and omits a pnpm
bump entry, which the compliance checklist requires for changesets. If pnpm is intended to track
this fix via changesets, this omission can prevent the correct release metadata from being recorded.
Code

.changeset/bound-pacquet-gzip-hints.md[R1-3]

+---
+"pacquet": patch
+---
Evidence
The compliance checklist requires each changeset to include a pnpm entry with a valid bump type.
The added changeset front-matter contains only pacquet, so it does not meet that requirement.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/bound-pacquet-gzip-hints.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The newly added changeset does not include a `pnpm` package bump entry, which is required by the compliance checklist.

## Issue Context
The changeset currently declares only `"pacquet": patch`. Per the checklist, changeset front-matter must also explicitly declare a `pnpm` bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/bound-pacquet-gzip-hints.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pnpm/crates/tarball/src/lib.rs (1)

2462-2474: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Extract unrelated changes to maintain scope discipline.

The PR objective indicates that this PR is dedicated to bounding gzip size hints to prevent oversized preallocations. However, it also bundles an unrelated error code refactor and a new manifest_subdir resolution feature. As per path instructions from REVIEW_GUIDE.md, please strictly follow scope discipline by limiting PRs to one logical change and only touching files justified by the mitigation.

Please extract these unrelated changes into separate pull requests:

  • pnpm/crates/tarball/src/lib.rs#L2462-L2474: revert the addition of the manifest_subdir field.
  • pnpm/crates/tarball/src/lib.rs#L148-L152: revert the diagnostic error code renames (and the corresponding renames on the remaining variants).
  • pnpm/crates/tarball/src/lib.rs#L2512-L2546: revert the manifest_subdir matching and store index suppression logic.
  • pnpm/crates/tarball/src/lib.rs#L2558-L2589: revert the read_subdir_manifest helper function.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/tarball/src/lib.rs` around lines 2462 - 2474, Limit this PR to
the gzip size-hint bounding change by reverting the unrelated additions in
pnpm/crates/tarball/src/lib.rs: remove manifest_subdir at lines 2462-2474,
restore the original diagnostic error codes and remaining variants at lines
148-152, remove manifest_subdir matching and store-index suppression at lines
2512-2546, and remove the read_subdir_manifest helper at lines 2558-2589.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@pnpm/crates/tarball/src/lib.rs`:
- Around line 2462-2474: Limit this PR to the gzip size-hint bounding change by
reverting the unrelated additions in pnpm/crates/tarball/src/lib.rs: remove
manifest_subdir at lines 2462-2474, restore the original diagnostic error codes
and remaining variants at lines 148-152, remove manifest_subdir matching and
store-index suppression at lines 2512-2546, and remove the read_subdir_manifest
helper at lines 2558-2589.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0e50bef5-83e1-479c-8df8-785f0d5b830c

📥 Commits

Reviewing files that changed from the base of the PR and between a1541d0 and f2406a7.

📒 Files selected for processing (3)
  • .changeset/bound-pacquet-gzip-hints.md
  • pnpm/crates/tarball/src/lib.rs
  • pnpm/crates/tarball/src/tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • .changeset/bound-pacquet-gzip-hints.md
  • pnpm/crates/tarball/src/tests.rs

zkochan added 2 commits July 17, 2026 14:19
Hoisting the 64 MiB cap to a shared constant moved it away from the
comment that justified it, leaving the rationale at the zip call site
while the constant itself carried none. That site also restated "64 MiB"
in prose directly above the named constant, which is the drift the shared
constant exists to prevent.

State the why once at the constant: both hint sources are
attacker-controlled, and post-download work runs concurrently, so a
per-task reservation is multiplied across every task in flight.

Document why the gzip path drops an oversized hint instead of clamping
it, since the two call sites deliberately differ. zune-inflate turns the
hint into an infallible zero-filled `vec![0; hint]`, so clamping would
let any package that overstates its size pin the whole ceiling up front.
The zip path can clamp because its `try_reserve` reports a refusal as an
error rather than aborting.
The existing test exercises `bounded_gzip_size_hint` in isolation, so
nothing caught `decompress_gzip` forwarding `dist.unpackedSize` straight
to zune-inflate — the security-relevant wiring the fix depends on.

Decompress a real gzip payload with an oversized hint and assert the
output. Verified the test bites by reverting the guard: it fails on the
unbounded `vec![0; hint]` reservation.
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 4b0f5a2

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

@zkochan

zkochan commented Jul 17, 2026

Copy link
Copy Markdown
Member

Rebased onto the latest main, which resolves the blocker noted in the description: #13066 is merged, so the zizmor check now runs with the shared fix. Pushed two follow-up commits (638c19f, 4b0f5a2) — details at the end.

The fix itself holds up. I traced the path to confirm it is genuinely reachable rather than theoretical: dist.unpackedSize → manifest_unpacked_size (accepts any u64 that fits in usize) → decompress_gzip → zune-inflate's vec![0; hint]. That allocation is infallible and zero-filling, so an oversized registry value does not fail gracefully — it aborts the process, and post-download work runs concurrently under post_download_semaphore, multiplying it.

Three automated findings are being declined, with reasons:

Qodo: "Changeset missing pnpm entry" (Rule 713436)

.changeset/bound-pacquet-gzip-hints.md correctly omits "pnpm". AGENTS.md is explicit for Rust-only changes:

Do not add "pnpm" to a Rust-only changeset: in changesets, pnpm always means the TypeScript CLI package.

This change touches only pnpm/crates/tarball. No TypeScript source consumes dist.unpackedSize as an allocation hint — the TypeScript CLI does not reference it at all — so there is nothing to bump on that side. Adding "pnpm": patch would bump the TypeScript CLI for a fix that is not in it and publish a release note to TypeScript users for code they do not run.

Precedent is consistent: pacquet-only changesets such as git-importer-lockfile.md, pacquet-add-multiple-packages.md, and pacquet-err-pnpm-error-codes.md target "pacquet" alone, while genuine parity changes such as allow-symlinked-lockfile-reads.md name both. Rule 713436 appears not to encode the Rust-only carve-out.

CodeRabbit: "Extract unrelated changes to maintain scope discipline"

The manifest_subdir field, the read_subdir_manifest helper, and the diagnostic error-code renames are not part of this PR. They come from 7794d31 ("fix(resolving-git-resolver): read git package names during resolution", #13059), which is already merged into main and is an ancestor of this branch — confirmed with git merge-base --is-ancestor.

That review ran against the pre-rebase base (fb4639f8d2), so everything merged into main since then appears as this PR's work. The actual diff is three files: the changeset and pnpm/crates/tarball/src/{lib,tests}.rs.

CodeRabbit: changeset should document the ZIP bound

Answered in the thread — the ZIP clamp already exists on the base commit, so this PR does not change that path's behavior and the release note should not claim otherwise.

Follow-up commits

  • 638c19f docs(tarball): document the untrusted preallocation ceiling — hoisting the cap to a shared constant left its rationale behind at the ZIP call site, which also restated "64 MiB" in prose above the named constant. The why now lives once at the constant, including why the gzip path drops an oversized hint while the ZIP path clamps.
  • 4b0f5a2 test(tarball): cover the gzip size-hint wiring — the existing test exercises bounded_gzip_size_hint in isolation, so nothing caught decompress_gzip forwarding dist.unpackedSize straight to zune-inflate. Verified the new test bites by reverting the guard: it fails on the unbounded reservation.

Verified: 74 tests pass in pacquet-tarball, plus cargo fmt --check, clippy with --deny warnings, rustdoc with -D warnings, typos, and taplo via the pre-push hook.


Written by an agent (Claude Code, claude-opus-4-8).

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 17, 2026
Dropping an oversized `dist.unpackedSize` bounded the eager allocation
but also discarded the hint for genuinely large packages, leaving them to
grow from zune-inflate's 37 KB default in 4 KiB steps. Measured on an
80 MiB package: 72.3 ms dropped vs 11.4 ms clamped, a ~6x regression on
the install hot path for every package above the ceiling.

Clamping reaches the same ceiling. A lying hint reserves at most 64 MiB,
and `vec![0; 64 MiB]` is lazily backed, so untouched pages never become
resident: 20 concurrent tiny packages each claiming `usize::MAX` hold
+0.7 MiB RSS, against +1280 MiB were the pages eager. The decoder still
grows on demand, so an archive larger than the ceiling decodes in full —
verified by round-tripping 80 MiB through `decompress_gzip`.

This also makes the fix the smallest correct one: behavior now changes
only for figures above the ceiling, and matches the sibling zip entry
reservation, which has always clamped against the same bound.
@zkochan

zkochan commented Jul 17, 2026

Copy link
Copy Markdown
Member

Correcting my earlier comment: I defended the "drop the hint rather than clamp it" choice there, and measurement showed that reasoning was wrong. Switched to clamping in 4cd4bc7.

Two claims I made without measuring, both of which turned out to be false:

"Dropping the hint costs only buffer growth." It costs ~6x. With no hint, zune-inflate starts from its 37 KB default and resizes in 4 KiB steps — roughly 20,000 resizes for an 80 MiB package. Release build, best-of-3, decompressing 80 MiB:

hint strategy time
dropped 72.3 ms
truthful 80 MiB (pre-fix) 17.7 ms
clamped to 64 MiB 11.4 ms

Packages under the ceiling are unaffected either way — the hint passes through untouched — so this only hit the >64 MiB tail. But that tail is real (Electron, Playwright, Cypress, prebuilt native binaries) and it sits on the install hot path, which REVIEW_GUIDE.md ranks second.

"Clamping would let every package that overstates its size pin the whole ceiling up front." It does not. vec![0; 64 MiB] is lazily backed, so pages the decoder never writes never become resident. Measured with 20 concurrent tiny packages each claiming usize::MAX (matching post_download_semaphore's num_cpus * 2), every buffer held alive at once:

20 lying pkgs (usize::MAX hint) held: RSS +0.7 MiB (eager would be +1280 MiB)

Clamping costs ~+0.6 MiB RSS over dropping, for a ~6x decode speedup.

So clamping reaches the same 64 MiB ceiling, keeps the reservation the hint exists for, and is the smaller change: behavior now differs from pre-fix code only for figures above the ceiling, rather than also penalizing honest large packages. It also matches the sibling zip entry reservation, which has always clamped against this same bound — the two paths no longer diverge, which removes the asymmetry I documented in 638c19f.

Verified an archive above the ceiling still decodes in full — 80 MiB round-tripped through decompress_gzip with a truthful 80 MiB hint, length and content asserted. The decoder grows on demand, so the ceiling bounds the eager reservation only, never the output. The pre-existing 1 GiB DeflateOptions::limit is untouched.

Boundary tests updated: MAX + 1 and usize::MAX now clamp to the ceiling rather than yielding None. Re-confirmed the wiring test still catches a regression by reverting the guard — it fails on the unbounded vec![0; hint].


Written by an agent (Claude Code, claude-opus-4-8).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 4cd4bc7

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

The ceiling's doc justified clamping by contrasting it against dropping
the hint, an alternative that exists only in this branch's history and
that a reader of the merged code cannot see. It also pinned zune-inflate
internals (a 37 KB default, 4 KiB growth steps) that will rot. State the
guarantee instead: the bound applies to the reservation, not the output.

`bounded_gzip_size_hint` opened by narrating its own body, and the wiring
test restated both the callee's rationale and its own assertion. Keep the
gzip-specific why on the helper, and let the test's doc carry only the
reason it exists next to the helper's unit test.
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 0c58e3d

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

Comment on lines +472 to +474
fn bounded_gzip_size_hint(unpacked_size: Option<usize>) -> Option<usize> {
unpacked_size.map(|size| size.min(MAX_UNTRUSTED_PREALLOC_BYTES))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Clamps rather than omits oversized hints

The PR description and squash commit body both say "Hints above the ceiling are omitted rather than clamped, allowing legitimate large archives to keep decoding through normal buffer growth." The implementation does the opposite: .min(MAX_UNTRUSTED_PREALLOC_BYTES) always returns Some(64 MiB) for oversized inputs. With many concurrent downloads of large packages each hint-over-limit task still eagerly reserves 64 MiB upfront. The tests also assert the clamping behavior.

If the intent is truly to omit oversized hints (so no eager allocation occurs for hints beyond the ceiling), the function body should use .filter instead: unpacked_size.filter(|&size| size <= MAX_UNTRUSTED_PREALLOC_BYTES). If clamping is the deliberate design, the PR description, squash commit body, and test assertions all need to be updated to say "clamped" rather than "omitted."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, and thank you — the second reading is right: clamping is deliberate, and the prose was stale. I switched the implementation from omitting to clamping in 4cd4bc7 and failed to update the description alongside it.

Fixed by updating the Summary and the Squash Commit Body, which now describe clamping and carry the measurements behind the choice. That mattered more than a stale description: the Squash Commit Body becomes the permanent commit message on main, so merging as-is would have written a false record into git history. The test assertions already match the implementation, so they stand as-is.

On the memory concern — "with many concurrent downloads of large packages each hint-over-limit task still eagerly reserves 64 MiB upfront" — that was my worry too, and it's why the code originally omitted. It does not hold up under measurement. vec![0; 64 MiB] is lazily backed, so pages the decoder never writes never become resident. With 20 concurrent tiny packages each claiming usize::MAX (matching post_download_semaphore's num_cpus * 2), every buffer held alive at once:

20 lying pkgs (usize::MAX hint) held: RSS +0.7 MiB (eager would be +1280 MiB)

Clamping costs ~+0.6 MiB RSS over omitting, and buys ~6x on decode: an 80 MiB package goes from 72.3 ms to 11.4 ms, because an omitted hint leaves the decoder growing from its 37 KB default in 4 KiB steps. Full numbers are in the description.

Worth flagging the one limit of that evidence: it is measured on macOS. Linux and macOS both mmap large allocations with lazily-zeroed pages, so it should carry over, but two configurations charge committed memory even when untouched — Linux with vm.overcommit_memory=2, and Windows commit charge. I judged that acceptable because the sibling zip entry reservation has always clamped against this same 64 MiB bound, so clamping the gzip hint introduces no exposure the module did not already accept.


Written by an agent (Claude Code, claude-opus-4-8).

@zkochan
zkochan merged commit 068a4cc into pnpm:main Jul 17, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants