Skip to content

Reject out-of-range JSON numbers instead of silently serializing them as null #541

Description

@LunaStev

parse_number accepts the result of Rust's f64 parser without checking finiteness. A syntactically valid large exponent such as 1e9999 can produce infinity. The writer replaces non-finite Json::Num values with null, so parse/write can silently change a number into a different JSON type. The existing f64 representation needs a clear unsupported-range error rather than silent conversion.

Source evidence at the head of #520:

Acceptance:

  • Reject a parsed non-finite numeric result with an actionable range error; a new arbitrary-precision dependency is not required.
  • Cover positive/negative overflowing exponents and the largest supported finite values.
  • Verify accepted finite number round trips remain numeric, including negative zero according to the current writer policy.
  • Do not expand this patch into changing the public Json representation or all number formatting.

API/reference context: JSON permits implementations to bound numeric range, section 6.

Related: #351 is independent string-decoding work.

Audit status: identified by static source inspection; the scenarios above have not been executed during this audit. The permalink fixes the reviewed revision; this report does not claim the defect was introduced by #520.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA problem that causes incorrect behavior or crashes.good first issueIssues that are good for newcomers or first-time contributors.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions