Repository navigation
npm: ignore data after a tarball's end of archive and gzip padding, as npm does - #868
Merged
Merged
Conversation
…s npm does node-tar ends an archive at two zero blocks in a row and reads nothing after them, and Node's zlib stops at the first zero byte after a gzip member. Forge refused non-zero data in both places, so a tarball npm installs was refused (a cached 502 through a proxy repository). Accept and ignore what follows the second zero block (still inflated within the unpacked bound) and what follows the gzip padding's first zero byte. The block after a lone zero block, which node-tar reads as a header, must still be zeros, so no entry npm reads is hidden from Forge. Fixes #599 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012e6DJZWVNoh4qBxyUBMv29
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.
Fixes #599
What changes
Since #554,
crates/formats/npm/src/tarball.rsrefused non-zero bytes anywhere after the tar crate's end of archive and after gzip's trailing zero padding. npm reads less than that, so Forge refused tarballs npm installs. On a proxy repository that is a cached 502. The reader now ignores exactly what npm ignores:SAW_EOFat the second zero block in a row and reads nothing after it. Forge now ignores what follows, whether it is junk or a whole entry. It still inflates it withinmax_unpacked, as npm does, but leaves it out ofdist.unpackedSize.Gunzipnow ends there too and never inflates the rest. Before, it demanded zeros up to the end of the input.What is still refused (#554's protection)
tarcrate ends at the first zero block, so this block must still be all zeros. An entry npm would read there (a laterpackage/package.jsonwith aninstallscript) is still refused. Forge never reads fewer entries, or other ones, than npm installs.Checked against npm's own node-tar
I built six tarballs and extracted each with npm 10.9.9's bundled node-tar (
tar.x,strip: 1). Forge'starball::readreturned the samepackage.jsonfor each, and refused the one-lone-zero-block case:0xffaapackage.jsonaapackage.jsonb(install script)\0,junkaaaabbTests
ignores_data_after_the_end_of_the_archivecovers junk and a whole entry after the two zero blocks, and the unpacked bound on that tail. It also checks that an entry, or junk, after a lone zero block is still refused.reads_every_gzip_membernow covers junk and another member after the padding being ignored, and junk right after a member being refused.refuses_data_after_a_lone_zero_block(renamed) also covers junk in that block.cargo fmt --all --check,cargo clippy -p forge-format-npm --all-targets -- -D warnings,cargo test -p forge-format-npmandcargo xtask changelog --checkall pass.Docs and changelog
docs/npm.md: the refusal list now says "data after a lone zero block".docs/changes/2.2.0/599.fixed.md.Generated by Claude Code