Skip to content

fix(cli): cap the gateway's manifest pull at the manifest size - #2477

Merged
thiras merged 2 commits into
mainfrom
fix/gateway-manifest-cap
Oct 16, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/gateway-manifest-cap

Conversation

@thiras

@thiras thiras commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What

The gateway reads a bundle manifest into memory for /<hash>/ and /<hash>/<path>. That pull ran under the gateway's normal --max-blob-mb (1 TiB by default), and the 64 MiB limit was checked only on bytes already read. So a request for a large non-manifest blob paid for 64 MiB plus the lanes' read-ahead before it failed with a 502. Anyone who could reach the gateway could spend the operator's funds this way.

  • fetch.rs: the clamp fetch_entry_hash already applied is now manifest_cap_mb (0 → 64, otherwise min(_, 64)), shared with the gateway.
  • gateway.rs: start_pull takes the cap. manifest passes manifest_cap_mb(self.common.max_blob_mb) and stream passes the gateway's own cap, which is unchanged. The client driver ends with BlobTooLarge before it opens a leg past the cap.
  • A new PullError::NotManifest covers a BlobTooLarge from the manifest pull, the in-loop byte guard and a BundleManifest::parse failure. It answers 404 (like the sibling "the bundle has no entry"), not 502, because nothing upstream failed. Funding passes through, so the capability-retry loop is unchanged.
  • A malformed entry hash now names its entry, as fetch::entry_hash does.
  • The 404 names the raw blob's gateway path (with ?ns=) only when the gateway serves it: with --max-blob-mb at or below 64, the raw fetch hits the same cap, so no hint is given.

Closes #2474

Reviewer notes

  • Read Gateway::manifest and over_manifest_cap first.
  • The cap bounds cost per request to at most the cap. It does not make an oversize blob free: the drive pulls up to the cap and then ends. Two things are left out of scope:
    • a negative cache for hashes found not to be manifests (the verdict is permanent for content-addressed bytes), and
    • refusing on the probe's unverified size claim before any leg opens.
  • With an operator --max-blob-mb below 64, a real manifest over that cap also answers 404. The message names the effective cap.

Verification

  • cargo fmt -- --check
  • cargo clippy -p decdn-cli --all-targets --all-features -- -D warnings (and the pre-commit clippy/doc hooks)
  • cargo nextest run -p decdn-cli: 814 passed
  • CARGO_BUILD_WARNINGS=deny cargo doc -p decdn-cli --no-deps --document-private-items
  • Mutation checks:
    • dropping the clamp in manifest fails a_manifest_pull_is_capped_and_an_oversize_blob_is_not_found;
    • mapping NotManifest to 502 fails both 404 tests;
    • dropping the conversion on finished fails a_cap_stop_after_the_first_bytes_is_not_found (the real client stops after the cap's worth has landed);
    • always giving the raw-blob hint fails the --max-blob-mb 10 check.
  • a_bundle_serves_its_index_and_entries: a valid manifest serves its entry and index with 200, and the manifest is pulled once under the manifest cap.
  • User-visible change: CHANGELOG.md entry added
  • contracts/ changed: n/a
  • Design change: n/a
  • PR title type fix, lowercase subject

🤖 Generated with Claude Code

The gateway read a bundle manifest under its normal --max-blob-mb (1 TiB
by default) and checked the 64 MiB limit only on the bytes it had read.
A /<hash>/ or /<hash>/<path> request for a large non-manifest blob paid
for 64 MiB plus the lanes' read-ahead before it failed with a 502.

The manifest pull now runs under manifest_cap_mb, the clamp that
decdn get's entry fetch already applies, so its lanes request no byte
past the cap. A blob over the cap, or one that does not parse as a
manifest, is PullError::NotManifest and answers 404: nothing upstream
failed. A malformed entry hash now names its entry.

Closes #2474

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 16, 2026 11:59
@thiras thiras self-assigned this Oct 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused changes preserve normal streaming and funding retries, with regression coverage and no identified blocking issues.

0 open findings

What changed in this PR

Bounds gateway manifest pulls to 64 MiB or the operator’s lower limit, reducing unnecessary paid downloads.

Changes:

  • Shares the manifest cap between CLI fetches and gateway pulls.
  • Returns 404 for oversized or invalid manifests while preserving funding retries.
  • Adds regression tests and a changelog entry.
File Description
crates/​cli/​src/​commands/​gateway/​tests.rs Tests pull caps and manifest error responses.
crates/​cli/​src/​commands/​gateway.rs Applies manifest limits and maps errors to 404.
crates/​cli/​src/​commands/​fetch/​tests.rs Tests shared cap calculation.
crates/​cli/​src/​commands/​fetch.rs Extracts the shared manifest cap helper.
CHANGELOG.md Documents bounded pulls and updated responses.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Review follow-up on #2474. The manifest 404 told the caller to fetch
`/<hash>` for the raw blob even when the gateway's own --max-blob-mb is
at or below the manifest cap, where that fetch hits the same cap and
answers 502. The hint now names the real path, with its ?ns=, and only
appears when the gateway's cap is higher. The read loop's backstop calls
the bytes a blob, not a manifest.

Tests: a cap stop that arrives after the first manifest bytes (the real
client's timing), a valid bundle that serves its entry and index with
the manifest pulled once, and the hint's gating.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 4675390 fix/gateway-manifest... 07bdcab +/-
75% 75% 0%
View coverage of the 8 most impacted files.
File main 4675390 fix/gateway-manifest... 07bdcab +/-
crates/node/src/dht/publish.rs 80% 78% -2%
crates/client/src/lib.rs 89% 88% -1%
crates/node/src...s/client/mod.rs 90% 89% -1%
crates/client/src/scheduler.rs 94% 94% 0%
crates/node/src...gin/pull_leg.rs 85% 85% 0%
crates/protocol/src/framing.rs 93% 93% 0%
crates/cli/src/...mmands/fetch.rs 50% 51% +1%
crates/cli/src/...ands/gateway.rs 43% 69% +26%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@thiras
thiras merged commit 0695b2b into main Oct 16, 2026
31 checks passed
@thiras
thiras deleted the fix/gateway-manifest-cap branch October 16, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gateway: cap the manifest pull at MAX_MANIFEST_MB so a non-manifest hash cannot cost 64 MiB

2 participants