Range::bytes and ContentRange::bytes do unchecked u64 arithmetic on bounds
評価
調査の方向性
Start with src/common/range.rs and src/common/content_range.rs at the reported arithmetic lines, then run the supplied reproducer in debug and release profiles. Done means empty or unrepresentable bounds return InvalidRange or InvalidContentRange rather than panic or emit wrapped HTTP ranges.
索引モデルが issue の本文から書いたものです。
説明
Range::bytes and ContentRange::bytes convert range bounds with unchecked u64 arithmetic. Debug builds panic with "attempt to subtract with overflow". Release builds wrap to u64::MAX and emit headers describing a 2^64-byte span, and empty ranges with a non-zero start emit bytes=N-(N-1) in both profiles.
Crate version: headers 0.4.1, no feature flags.
Reproducer
use headers::{ContentRange, Header, HeaderValue, Range};
fn encode<H: Header>(h: &H) -> String {
let mut values: Vec<HeaderValue> = Vec::new();
h.encode(&mut values);
values[0].to_str().unwrap().to_owned()
}
fn main() {
println!("{}", encode(&Range::bytes(0u64..0u64).unwrap()));
println!("{}", encode(&Range::bytes(3u64..3u64).unwrap()));
println!("{}", encode(&ContentRange::bytes(0u64..0u64, 500u64).unwrap()));
println!("{}", encode(&ContentRange::bytes(0u64.., 0u64).unwrap()));
println!("{}", encode(&ContentRange::bytes(3u64..3u64, 100u64).unwrap()));
}
Observed
cargo run --release prints:
bytes=0-18446744073709551615
bytes=3-2
bytes 0-18446744073709551615/500
bytes 0-18446744073709551615/0
bytes 3-2/100
cargo run in debug panics on the first call at src/common/range.rs:56, so the program prints nothing. Run on their own in a debug build, ContentRange::bytes(0u64..0u64, 500u64) panics at src/common/content_range.rs:66 and ContentRange::bytes(0u64.., 0u64) panics at src/common/content_range.rs:68.
Expected
All five calls should return Err(InvalidRange) or Err(InvalidContentRange). Both constructors return a Result so unrepresentable bounds can be rejected. RFC 7233 section 2.1 requires last-byte-pos >= first-byte-pos in a byte-range-spec, so bytes=3-2 is invalid. RFC 7233 section 4.2 adds last-byte-pos < complete-length, which rules out bytes 0-18446744073709551615/0.
Root cause
src/common/range.rs:56:format!("bytes={}-{}", start, end - 1)src/common/content_range.rs:66:Bound::Excluded(&e) => e - 1,src/common/content_range.rs:68:Some(max) => max - 1,src/common/content_range.rs:60:Bound::Excluded(&s) => s + 1,, the mirrored addition on an excluded start bound. Not exercised here.
Scope
Any empty half-open range N..N passed to either constructor. Any ContentRange::bytes call with an unbounded end and complete_length == 0. Those 0..0 and zero-length forms panic in debug and wrap in release. The non-zero empty forms are silent in both.
- 主要言語
- Rust
- スター
- 200
- フォーク
- 108
- 平均マージ
- 3日 2時間
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
hyperium/headers のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
From<SystemTime> for HttpDate panics on times before 1970 or after year 9999対応中かも @SAY-5 が 76 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
Link supportオープン
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
Access-Control-Request-Headers should not use a space when combining対応中かも @youdie006 が 53 日前に担当しました。 オープンeasy
難易度 2/5 1〜3時間 初心者へのやさしさ 50/100
hyperium/headers の issue をすべて見る
似ている issue
-
bug user-priority/P2
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
rescript-lang/rescript#8765 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nautechsystems/nautilus_trader#5287 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
farion1231/cc-switch#8072 ·
メンテナーはふだん 1 日以内に返信
-
Python 3.15 support対応中かも @amnesiaof が今日担当しました。 オープンL: python L: python:uv
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dependabot/dependabot-core#16524 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信