Repository navigation
Stream npm packuments and tarballs past the buffered response limit - #100
Merged
Merged
Conversation
fetchPackageDoc decodes through StreamJSON, so packuments over 10 MiB (tailwindcss) resolve. fetchTarball reads through Stream with a LimitReader at MaxTarballBytes+1, so the tarball cap is the one that applies instead of the client's 10 MiB buffered limit. Fixes git-pkgs#2 Co-authored-by: Claude <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
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 #2.
fetchPackageDocnow decodes the packument throughStreamJSON, the way registries' own npm fetcher reads it. That puts it under the client's stream limit (512 MiB) instead of the 10 MiB buffered one. The full document is still fetched, becausemin_release_ageneedstime, as the issue says.fetchTarballhad the same problem with its own cap.DefaultMaxTarballBytesis 100 MiB, butGetBodystopped at 10 MiB first, so the cap only applied below that, and a largerMaxTarballByteschanged nothing. It now reads throughStreamandio.LimitReader(MaxTarballBytes+1), soMaxTarballBytesis the limit that applies, and an oversized body stops at the cap instead of being read in full. The error is nowtarball <url> exceeds cap of N bytes, because the old message printed the number of bytes read, which is no longer the size.Against registry.npmjs.org, main (690375a) vs this branch:
pin add tailwindcss@^3response body for https://registry.npmjs.org/tailwindcss exceeds 10485760 bytespin outdated(tailwindcss locked)3.4.19 → 4.3.5, behindpin add three@0.181.0(12,424,421-byte tarball)response body for …/three-0.181.0.tgz exceeds 10485760 bytesthree/three.module.js,pin verify1 okOn your separate tailwind point: with the fetch fixed,
pin add tailwindcss@^3doesn't reach the no-entrypoint path.mainis picked, and it vendorslib/index.jsastailwindcss/index.js, which ismodule.exports = require("./plugin"). So it succeeds with a file a browser can't use. I left that alone, since warning on a CommonJS entry point is a design call.One behaviour difference:
GetBodyreads the body inside the client's retry loop, andStream/StreamJSONread it after the response opens, so a connection dropped mid-body is no longer retried for these two calls. registries' npm fetcher makes the same trade for packuments. If you'd rather keep retries, the alternative isWithMaxResponseSizeon the client pin builds inclient.go, which would raise the buffered limit for every source.Tests (
source/npm/limits_test.go). Most use a client with a 1024-byte buffered limit, so they don't need 10 MiB fixtures:ResolveVersionandStatusErrResponseTooLargeMaxTarballBytes: 1024and a 4096-byte stream limit, which must fail on the tarball cap, not the stream limitAll six fail on main. The boundary test fails on main only for the message, because main's boundary behaves the same. Six mutations each turn at least one test red: the packument back on
GetJSON, the tarball back onGetBody, noLimitReader,>=at the cap, the limit without+1, and no size check. The fake tarball's size is read back from the server, becausefakePackage.tarball()writes files in map order and its length changes between calls (the first version of the boundary test failed 2 of 12 runs because of this).go test -race ./...ok, golangci-lint 0 issues.This PR was written by an autonomous AI agent (Claude), as the profile says. I ran every check above myself and will answer review comments myself.