Repository navigation
fix(node): bound buyer-side pull to max_blob_size, reject oversized total_bytes (#840) - #881
Conversation
…otal_bytes (#840) The node-to-node cache-miss pull (`fetch_inner`) buffered up to a server-controlled `total_bytes` with no local ceiling. `total_bytes` is signed but `StreamResponse::validate()` never bounds it, so the in-loop `cumulative > expected` guard only caps growth at the server's own promise — one inflated claim could drive the buying node toward OOM before any hash check. The serving side already enforces the inverse gate (`BlobTooLarge`); the buyer side did not. Thread the node's `max_blob_size_bytes` (from `cache.max_blob_size_mb`, the same derivation as the serving gate) into the buyer pull path and reject an oversized `total_bytes` before the receive loop / allocation. `0` = unlimited, matching the serving-side convention. Classify the rejection correctly: it returns a typed `BlobTooLargeClaim` sentinel that `pull_from_candidate` recognizes as a buyer-side policy decision (OUR ceiling, not the provider's fault — it may legitimately serve larger blobs to nodes with a higher ceiling). Like the channel-open failure, it records a dedicated `node_pull_too_large` counter and tries the next candidate WITHOUT folding reputation — avoiding a false "provider unreachable" signal on the gossip feed. Tests: a loopback reject + exact-ceiling-accepted boundary, and a production-orchestration test asserting the clean NotFound, no reputation observation, and the counter — all proven to fail when the gate/classification is disabled. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements a buyer-side blob size ceiling check to reject oversized blobs before buffering or paying, preventing potential out-of-memory (OOM) issues. It introduces the BlobTooLargeClaim error sentinel, updates the fetching logic to enforce max_blob_size_bytes, adds corresponding metrics, and integrates tests verifying both loopback and orchestration behavior. The review feedback highlights a potential vulnerability where a server claiming a total_bytes value less than the requested byte_offset could bypass verification, and suggests validating that total_bytes is at least equal to byte_offset.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR closes an OOM vector in the node-to-node paid pull path by enforcing a buyer-side blob size ceiling: if an upstream claims a total_bytes larger than the local node’s configured maximum, the buyer rejects the stream before buffering/allocating. It also classifies this rejection as a buyer-side policy decision (not a provider fault), emitting a dedicated metric and avoiding reputation impact.
Changes:
- Add a buyer-side
total_bytesceiling check instream_fetch_tracked/fetch_inner, returning a typedBlobTooLargeClaimsentinel for proper orchestration classification. - Wire
cache.max_blob_size_mb * MB_BYTESintoNodeOriginConfigand pass it through the production pull path. - Add metrics and regression tests covering oversized claims, boundary acceptance, and “no reputation scoring” behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/client_requester.rs | Adds max_blob_size_bytes parameter plumbing and rejects oversized total_bytes early via typed BlobTooLargeClaim. |
| crates/node/src/node_origin.rs | Threads max_blob_size_bytes into pulls and classifies oversized-claim failures as buyer policy (no reputation ding), recording a dedicated metric. |
| crates/node/src/runtime/mod.rs | Populates NodeOriginConfig.max_blob_size_bytes from cache.max_blob_size_mb * MB_BYTES. |
| crates/node/src/metrics.rs | Introduces node_pull_too_large counter and a convenience increment method. |
| crates/node/tests/client_loopback.rs | Adds loopback tests for buyer-side rejection of oversized claims and inclusive boundary acceptance. |
| crates/node/tests/node_origin_pull.rs | Adds orchestration-level test ensuring oversized-claim rejection increments metric and does not emit reputation observations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 86.12% (was 85.87%, ▲ +0.26%) — 34967/40601 lines
History
|
A server claiming `total_bytes < byte_offset` underflows `expected` to 0 (saturating_sub), so the receive loop ends on the first StreamEnd and returns an empty buffer. On a resumed fetch (`byte_offset > 0`) the whole-blob BLAKE3 check is skipped, so that empty/short buffer would surface as success — a silent verification bypass. Reject any `total_bytes < byte_offset` before the loop; a legitimate server always claims `total_bytes >= byte_offset`. Latent today (the production pull path passes `byte_offset = 0`), but a defensive guard on the same server-controlled `total_bytes` field the buyer-side ceiling already hardens. Flagged in review. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The total_bytes < byte_offset guard only closed the degenerate point of a range: it caught expected underflowing to 0 (empty buffer), but a non-empty *short* delivery — total_bytes >= byte_offset yet the server sends fewer than `expected` bytes then StreamEnd — still returned Ok with a truncated buffer. The StreamEnd arm breaks unconditionally and the whole-blob BLAKE3 check is skipped for byte_offset > 0, so the short read surfaced as success with no integrity recourse. Add a post-loop completeness check requiring the full promised remainder, scoped to byte_offset > 0. A full fetch (byte_offset == 0) stays hash-authoritative and may legitimately be shorter than an over-claimed total_bytes as long as the bytes hash correctly, so it is deliberately excluded. Narrow the prior guard's comment to "empty" (it only produces the empty case; this check covers short). Latent today (production passes byte_offset = 0); defensive hardening of the resume path against a dishonest total_bytes, completing the prior guard. Flagged in review. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Summary
Fixes #840 — the node-to-node cache-miss pull buffered up to a server-controlled
total_byteswith no local ceiling, an OOM vector.total_bytesis signed butStreamResponse::validate()never bounds it, so the in-loopcumulative > expectedguard only caps growth at the server's own promise; one inflated claim could drive the buying node toward OOM before any hash check. The serving side already enforces the inverseBlobTooLargegate — the buyer side did not.What changed
client_requester.rs): thread the node'smax_blob_size_bytesintostream_fetch_tracked→fetch_innerand reject an oversizedtotal_bytesbefore the receive loop / allocation.0= unlimited, mirroring the serving-side gate. Derived fromcache.max_blob_size_mbvia the same× MB_BYTESexpression as the serving side, so the two ceilings can't drift.node_origin.rs,runtime/mod.rs): addmax_blob_size_bytestoNodeOriginConfig, populate it from config, and pass it at the productionpull_from_candidatecall site.node_origin.rs,metrics.rs): the rejection returns a typedBlobTooLargeClaimsentinel.pull_from_candidaterecognizes it as a buyer-side policy decision — OUR ceiling, not the provider's fault (it may legitimately serve larger blobs to nodes with a higher ceiling). Like the channel-open path, it records a dedicatednode_pull_too_largecounter and tries the next candidate without folding reputation, avoiding a false "provider unreachable" signal on the gossip feed.Why the typed sentinel
A bare
bail!would land inpull_from_candidate'selsearm →Outcome::Unreachable(uptime_observed: false), gossiping that a reachable provider is down. The sentinel routes it to an explicit, no-reputation-ding arm with its own metric.Tests
buyer_rejects_oversized_total_bytes— server unlimited / buyer ceiling below the blob; assertsBlobTooLargeand no voucher paid.buyer_accepts_blob_at_exact_ceiling— boundary: the gate is strict (>), so an exactly-ceiling-sized blob is accepted (guards a>→>=regression).node_origin_oversized_claim_is_rejected_without_scoring— drives the realOrigin::fetchorchestration; asserts cleanNotFound, no reputation observation, neutral score, andnode_pull_too_large_total == 1.All three proven to fail when the gate/classification is disabled.
Verification
cargo fmt --check,cargo clippy --all-targets -p decdn-node,cargo build --workspace— cleancargo nextest run -p decdn-node→ 590/590 pass (+2 net new)🤖 Generated with Claude Code