fix(acl): map NaN/\u00b1Infinity to JSON null instead of panicking#15482
Open
thanhtoantnt wants to merge 1 commit into
Open
fix(acl): map NaN/\u00b1Infinity to JSON null instead of panicking#15482thanhtoantnt wants to merge 1 commit into
thanhtoantnt wants to merge 1 commit into
Conversation
From<Value> for serde_json::Value was calling serde_json::Number::from_f64(f).unwrap(), which panics for non-finite f64 values (NaN, +Infinity, -Infinity) because the JSON spec (RFC 8259) does not permit them. Replace the unwrap with an explicit match: finite floats produce a JSON Number as before; non-finite values produce JSON null, matching the IEEE 754 null-substitution convention used by many JSON serializers. Fixes tauri-apps#15477
| Value::Bool(b) => serde_json::Value::Bool(b), | ||
| Value::Number(Number::Float(f)) => { | ||
| serde_json::Value::Number(serde_json::Number::from_f64(f).unwrap()) | ||
| match serde_json::Number::from_f64(f) { |
Contributor
There was a problem hiding this comment.
As much as this is a problem, from how we use this today, a crash might be better than silently making it null here.
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.
closes #15477
What changed
From for serde_json::Value in crates/tauri-utils/src/acl/value.rs was calling serde_json::Number::from_f64(f).unwrap(). The JSON spec (RFC 8259 §6) does not permit non-finite
floats, so from_f64 returns None for NaN, +Infinity, and -Infinity — and the .unwrap() turns that into an unconditional panic.
Number::Float accepts any f64 via From, so non-finite values are constructible without error and the panic was the first signal that anything was wrong — potentially surfacing
at an unrelated call site well after the bad value was created.
Non-finite floats now produce serde_json::Value::Null, consistent with the IEEE 754 null-substitution convention used by many JSON serializers.