Skip to content

fix(node): bound buyer-side pull to max_blob_size, reject oversized total_bytes (#840) - #881

Merged
thiras merged 3 commits into
mainfrom
fix/840-buyer-blob-size-ceiling
Jun 12, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/840-buyer-blob-size-ceiling

Conversation

@thiras

@thiras thiras commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #840 — the node-to-node cache-miss pull buffered up to a server-controlled total_bytes with no local ceiling, an OOM vector. 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 BlobTooLarge gate — the buyer side did not.

What changed

  • Gate (client_requester.rs): thread the node's max_blob_size_bytes into stream_fetch_tracked → fetch_inner and reject an oversized total_bytes before the receive loop / allocation. 0 = unlimited, mirroring the serving-side gate. Derived from cache.max_blob_size_mb via the same × MB_BYTES expression as the serving side, so the two ceilings can't drift.
  • Wiring (node_origin.rs, runtime/mod.rs): add max_blob_size_bytes to NodeOriginConfig, populate it from config, and pass it at the production pull_from_candidate call site.
  • Correct classification (node_origin.rs, metrics.rs): the rejection returns a typed BlobTooLargeClaim sentinel. pull_from_candidate recognizes 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 dedicated node_pull_too_large counter 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 in pull_from_candidate's else arm → 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; asserts BlobTooLarge and 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 real Origin::fetch orchestration; asserts clean NotFound, no reputation observation, neutral score, and node_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 — clean
  • cargo nextest run -p decdn-node → 590/590 pass (+2 net new)

🤖 Generated with Claude Code

…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]>
Copilot AI review requested due to automatic review settings June 12, 2026 20:07

@gemini-code-assist gemini-code-assist Bot 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.

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.

Comment thread crates/node/src/client_requester.rs Resolved

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.

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_bytes ceiling check in stream_fetch_tracked/fetch_inner, returning a typed BlobTooLargeClaim sentinel for proper orchestration classification.
  • Wire cache.max_blob_size_mb * MB_BYTES into NodeOriginConfig and 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.

@github-actions

github-actions Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 86.12% (was 85.87%, ▲ +0.26%) — 34967/40601 lines

File Coverage Lines Δ
crates/node/src/client_requester.rs 87.30% 275/315 ▲ +0.06%
crates/node/src/metrics.rs 83.70% 714/853 ▲ +0.06%
crates/node/src/node_origin.rs 90.11% 255/283 ▲ +0.21%
crates/node/src/runtime/mod.rs 49.55% 878/1772 ▼ 0.11%
History
Commit Total Δ vs base
d39d4c9 86.13% ▲ +0.26%
7297e22 86.13% ▲ +0.26%
b45b528 (HEAD) 86.12% ▲ +0.26%

thiras and others added 2 commits June 12, 2026 23:16
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]>
@thiras
thiras merged commit a5bc8ff into main Jun 12, 2026
20 checks passed
@thiras
thiras deleted the fix/840-buyer-blob-size-ceiling branch June 12, 2026 20:30
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.

node: buyer-side pull buffers up to server-claimed total_bytes with no blob-size ceiling (asymmetric with serving-side BlobTooLarge gate)

2 participants