Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

JSON parser rejects 0e400 because parse_f64_approx returns NaN for a zero mantissa with a large exponent

オープン 初心者向け
#990 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@auraseb がすでに取り組んでいます。

2026年10月18日 から。

  • #991 @auraseb による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
backend

調査の方向性

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

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/edit のほかの issue

microsoft/edit の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。