`SizeHint` addition overflows (panics in debug builds, wraps in release)
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
Issue では src/size_hint.rs が示されており、そこでは Add for SizeHint が境界を結合する際にオーバーフローします。まずその実装と近くにあるテストを読み、次に、提案されている飽和する下限とチェック付きの上限が既存の動作にどう適合するかを確認してください。加算時のオーバーフローで panic や値の折り返しが発生せず、テストで結果の境界がカバーされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
impl Add for SizeHint adds the lower and upper bounds with plain +, so it panics with "attempt to add with overflow" in debug builds when a sum exceeds u64::MAX. In release builds it wraps, and the result can be a hint whose bounds are smaller than either input.
// Cargo.toml: http-body = { git = "https://github.com/hyperium/http-body" }
use http_body::SizeHint;
fn main() {
let s = SizeHint::with_exact(u64::MAX) + SizeHint::with_exact(1);
println!("{:?} {:?}", s.lower(), s.upper());
}
Debug build:
thread 'main' panicked at http-body/src/size_hint.rs:95:20:
attempt to add with overflow
Release build: prints 0 Some(0).
I expected the sum to saturate at u64::MAX (a size hint that cannot be represented exactly is still a valid lower bound when saturated), or the overflow to be documented. Checked on master at c6ca645.
fn add(self, rhs: Self) -> Self::Output {
SizeHint {
lower: self.lower() + rhs.lower(), // overflows
upper: self.upper().and_then(|this| rhs.upper().map(|rhs| this + rhs)), // overflows
}
}
Suggested fix: self.lower().saturating_add(rhs.lower()), and for the upper bound checked_add, giving None (no upper bound) when the sum does not fit.
Kani harness that fails on master (cargo kani --harness add_does_not_overflow, appended to src/size_hint.rs):
#[cfg(kani)]
mod kani_proofs {
use super::SizeHint;
#[kani::proof]
fn add_does_not_overflow() {
let a = SizeHint::with_exact(kani::any());
let b = SizeHint::with_exact(kani::any());
let _ = a + b;
}
}
Failed Checks: attempt to add with overflow
File: "src/size_hint.rs", line 95, in <size_hint::SizeHint as std::ops::Add>::add
VERIFICATION:- FAILED
It takes about 1.6 s and under 200 MB.
This was found with Kani 0.68.0 in an experiment where AI agents verified popular crates using the Kani agent plugin (model-checking/kani#5059). The text was written with AI assistance; the reproducer and the Kani harness were re-run by hand on the commit named above.
- 主要言語
- Rust
- スター
- 173
- フォーク
- 71
- 平均マージ
- 1日 12時間
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
hyperium/http-body のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
Feature Proposal: Add `try_clone` method to `Body` trait対応中かも @pearzl が 380 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
Empty's Body impl `Error = Infallible` makes `Empty::new()` unable to be used w/ Body constraintsオープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
hyperium/http-body の issue をすべて見る
似ている issue
-
An EXE started from the shell with MAXALLOC FFFFh leaves a 0-paragraph free block after its ownオープンbug low-priority
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
dividebysandwich/rust-dos#629 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
eliasstravik/herdr-projects#758 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
enhancement needs:sonnet ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
kinqsradio/orbyn-engineering#297 ·
メンテナーはふだん 1 日以内に返信