JSON parser rejects 0e400 because parse_f64_approx returns NaN for a zero mantissa with a large exponent
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
crates/edit/src/float.rs、特に parse_f64_approx から始め、次に json::Parser::parse_number と既存の JSONパーサーのテストを調べる.Zero と大きな指数、および i32::MAX に近い値を再現し、パーサーが panic せずに有限な zero または infinity を返すようにします。0e400、-0e400、有効な大きな指数、JSON のパース動作を検証するテストを追加または更新します。
索引モデルが issue の本文から書いたものです。
説明
What happens
edit::float::parse_f64_approx returns NaN for a zero written with a large positive exponent, for example 0e400 or 0.0e999. f64::from_str returns 0.0 for the same input, and the module doc says the parser accepts the same grammar and differs by at most a few ULP.
Because json::Parser::parse_number rejects non finite numbers, the JSON value 0e400 (valid JSON, value zero) is reported as Invalid JSON when it appears in a settings file.
Separately, an exponent near i32::MAX (for example 1e2147483645) panics with attempt to add with overflow in debug and test builds.
What should happen
0e400 parses to 0.0 (and -0e400 to -0.0), and very large exponents return infinity or zero without panicking, matching f64::from_str.
Repro
use edit::float::parse_f64_approx;
assert_eq!("0e400".parse::<f64>().unwrap(), 0.0);
assert_eq!(parse_f64_approx(b"0e400"), Some(0.0)); // fails: Some(NaN)
let arena = edit::arena::scratch_arena(None);
edit::json::parse(&arena, "0e400").unwrap(); // Err: 1:6: Invalid JSON
parse_f64_approx(b"1e2147483645"); // debug build: attempt to add with overflow
Root cause
In crates/edit/src/float.rs the mantissa is scaled by 10f64.powi(exponent) whenever exponent != 0. For a zero mantissa and an exponent above about 308, powi returns infinity and 0.0 * inf is NaN.
The exponent is accumulated with saturating arithmetic, but the table lookup then computes exponent + 3 with a plain add, which overflows when the exponent saturated at i32::MAX.
- 主要言語
- Rust
- スター
- 14.7k
- フォーク
- 737
- 平均マージ
- 22時間 33分
- マージ済み PR(30日)
- 18
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/edit のほかの issue
-
Assertion fails when passing `C:` as command line argument対応中かも @rhysd が 507 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
microsoft/edit#367 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[bug]: Cursor misalignment occurs when displaying inline code in Markdown under word wrap対応中かも @xiaoditx が 30 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
microsoft/edit#948 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 75/100
microsoft/edit#947 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
microsoft/edit#904 · リアクション 4 件 ·
メンテナーはふだん 1 日以内に返信
-
C-task E-help-wanted P-medium
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
microsoft/edit#896 · コメント 4 件 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
good first issue gpu serve
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
biomejs/biome#12475 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
メンテナーはふだん 1 日以内に返信
-
documentation E-easy good first issue help wanted
難易度 1/5 1〜3時間 初心者へのやさしさ 91/100
メンテナーはふだん 1 日以内に返信