write_float writes null for NaN and infinity - #70
Open
yuxi-liu-wired wants to merge 1 commit into
Open
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
`BaseGenerator::write_float` passed every f64 to `ryu::Buffer::
format_finite`, whose output for non-finite input is unspecified. NaN
came out as `2.696539702293474e308` and infinity as
`1.797693134862316e308`, so simd-json serialized
simd_json::to_string(&f64::NAN) "2.696539702293474e308"
simd_json::to_string(&f64::INFINITY) "1.797693134862316e308"
(and the same from `Value::encode`). Both are valid JSON numbers but not
the value: the first reads back as infinity. JSON has no NaN or
infinity; serde_json writes `null`. `write_float` now does the same.
Test: `test_write_float_non_finite` (fails before this change).
Found by a differential fuzzer (serde_json, simd-json, sonic-rs, jiter)
extended to typed serialization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: write_float writes null for NaN and infinity
BaseGenerator::write_floatpassed every f64 toryu::Buffer:: format_finite, whose output for non-finite input is unspecified. NaNcame out as
2.696539702293474e308and infinity as1.797693134862316e308, so simd-json serialized(and the same from
Value::encode). Both are valid JSON numbers but notthe value: the first reads back as infinity. JSON has no NaN or
infinity; serde_json writes
null.write_floatnow does the same.Test:
test_write_float_non_finite(fails before this change).Testing
Each commit adds a regression test that fails before the change. The full test suite passes and
cargo fmt --checkis clean on the changed files.Found with a differential fuzzer comparing serde_json, simd-json, sonic-rs and jiter.