Skip to content

fix(bao-range): reject overlong range_data in encode_verified_range (#1055) - #1154

Merged
alpergundogdu merged 1 commit into
mainfrom
fix/1055-bao-range-overlong-guard
Jul 15, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
fix/1055-bao-range-overlong-guard

Conversation

@alpergundogdu

@alpergundogdu alpergundogdu commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1055

Summary

encode_verified_range in the decdn-bao-range leaf crate wraps range_data in an OffsetReadAt that only exposes the aligned fetch window [fetch_start, fetch_end). A range_data longer than aligned.fetch_len() (e.g. a corrupt origin 206 with an extra tail) had its surplus tail silently dropped; a shorter body surfaced only as an opaque verification short-read.

This adds a defensive size guard at the top of encode_verified_range: it now returns the new RangeVerifyError::RangeDataSize { expected, got, blob_size } variant when range_data.len() != aligned.fetch_len(), turning malformed origin input into a typed error instead of a silent truncation.

No integrity impact — the bytes that were imported were always bao-verified against the root, and the extra tail was never imported. This only surfaces malformed input that was previously dropped silently.

Changes

  • Add RangeVerifyError::RangeDataSize error variant.
  • Guard range_data.len() == aligned.fetch_len() before verification.
  • Add unit tests for the too-long and too-short cases.

Verification

  • cargo build — pass (full workspace)
  • cargo clippy --all-targets — pass, clean (full workspace)
  • cargo nextest run -p decdn-bao-range — 2 passed
  • cargo nextest run -p decdn-cache --test range_pull — 18 passed (downstream users of the enum, all use matches!(.., { .. }) so the new variant is source-compatible)
  • cargo fmt -- --check — pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Added a clear range data size error when fetched data is shorter or longer than the requested aligned range.
    • Prevented invalid responses from being silently truncated or reported as ambiguous verification failures.
    • Improved error details by reporting the expected size, received size, and blob size.
    • Added coverage for both truncated and overlong range data responses.

…1055)

The offset-mapped `OffsetReadAt` only exposes `[fetch_start, fetch_end)`,
so a `range_data` longer than `aligned.fetch_len()` (e.g. a corrupt origin
206 with an extra tail) had its surplus silently dropped; a shorter body
surfaced only as an opaque verification short-read.

Add a defensive size guard up front: `encode_verified_range` now returns the
new `RangeVerifyError::RangeDataSize { expected, got, blob_size }` when
`range_data.len() != aligned.fetch_len()`, turning malformed origin input
into a typed error instead of a silent truncation. No integrity impact — the
bytes imported were always bao-verified — this just surfaces bad input.

Add unit tests for the too-long and too-short cases.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI review requested due to automatic review settings July 15, 2026 11:00
@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: b392008c-7e4b-4ba6-8814-2748963dd989

📥 Commits

Reviewing files that changed from the base of the PR and between 6b10e7a and abb921c.

📒 Files selected for processing (1)
  • crates/bao-range/src/lib.rs

Walkthrough

Adds typed validation for mismatched origin range data lengths, documents the new error, and tests both overlong and truncated responses.

Changes

Range data validation

Layer / File(s) Summary
Typed size check and validation tests
crates/bao-range/src/lib.rs
Adds RangeVerifyError::RangeDataSize, checks range_data against the aligned fetch length before verification, documents the error, and tests overlong and truncated inputs.

Estimated code review effort: 2 (Simple) | ~10 minutes


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@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 introduces a new error variant RangeVerifyError::RangeDataSize to handle cases where the length of range_data does not match the expected aligned fetch window's length. It adds a size guard in encode_verified_range to reject overlong or truncated range data up front, and includes corresponding unit tests to verify this behavior. I have no feedback to provide.

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.

@github-actions

Copy link
Copy Markdown

Contracts coverage

Line coverage: 88.71% (2452/2764 lines)
▲ +0.00pp vs base (88.71% → 88.71%)
Run: 29410104225

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 hardens the decdn-bao-range leaf crate’s encode_verified_range path by rejecting malformed HTTP 206 range bodies whose payload size does not exactly match the aligned fetch window, preventing silent truncation of surplus bytes and replacing ambiguous verification short-reads with a typed error.

Changes:

  • Added a new RangeVerifyError::RangeDataSize { expected, got, blob_size } variant to represent mismatched range-body sizes.
  • Added an upfront range_data.len() == aligned.fetch_len() guard in encode_verified_range.
  • Added unit tests covering both overlong and too-short range_data inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 80.29% (was 80.28%, ● 0.00%) — 45265/56380 lines

File Coverage Lines Δ
crates/bao-range/src/lib.rs 93.88% 138/147 ▼ 2.61%
History
Commit Total Δ vs base
abb921c (HEAD) 80.29% ● 0.00%

@alpergundogdu
alpergundogdu merged commit a54f93d into main Jul 15, 2026
24 checks passed
@alpergundogdu
alpergundogdu deleted the fix/1055-bao-range-overlong-guard branch July 15, 2026 11:46
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.

decdn-bao-range: encode_verified_range should reject overlong range_data

2 participants