Repository navigation
fix(bao-range): reject overlong range_data in encode_verified_range (#1055) - #1154
Conversation
…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]>
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (1)
WalkthroughAdds typed validation for mismatched origin range data lengths, documents the new error, and tests both overlong and truncated responses. ChangesRange data validation
Estimated code review effort: 2 (Simple) | ~10 minutes Note 🎁 Summarized by CodeRabbit FreeYour 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 |
Gas snapshotNo gas changes vs base. |
There was a problem hiding this comment.
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.
Contracts coverageLine coverage: 88.71% (2452/2764 lines) |
There was a problem hiding this comment.
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 inencode_verified_range. - Added unit tests covering both overlong and too-short
range_datainputs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 80.29% (was 80.28%, ● 0.00%) — 45265/56380 lines
History
|
Closes #1055
Summary
encode_verified_rangein thedecdn-bao-rangeleaf crate wrapsrange_datain anOffsetReadAtthat only exposes the aligned fetch window[fetch_start, fetch_end). Arange_datalonger thanaligned.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 newRangeVerifyError::RangeDataSize { expected, got, blob_size }variant whenrange_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
RangeVerifyError::RangeDataSizeerror variant.range_data.len() == aligned.fetch_len()before verification.Verification
cargo build— pass (full workspace)cargo clippy --all-targets— pass, clean (full workspace)cargo nextest run -p decdn-bao-range— 2 passedcargo nextest run -p decdn-cache --test range_pull— 18 passed (downstream users of the enum, all usematches!(.., { .. })so the new variant is source-compatible)cargo fmt -- --check— pass🤖 Generated with Claude Code
Summary by CodeRabbit