Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"$serde_json::private::Number" positional dependence prevents round-tripping Values #826

Closed
saethlin opened this issue Nov 21, 2021 · 1 comment

Comments

@saethlin
Copy link

saethlin commented Nov 21, 2021

I'm experimenting with a new fuzz target, intending to find inputs that do not round-trip correctly. Instead, I found something quite different (than I expected). This example program crashes on the last line when the arbitrary_precision feature is turned on:

fn main() {
    let input = r#"{"C":0,"$serde_json::private::Number":0}"#;
    let value = serde_json::from_str::<serde_json::Value>(input).unwrap();
    let serialized = serde_json::to_string(&value).unwrap();
    println!("{:?}", serialized);
    let roundtrip = serde_json::from_str::<serde_json::Value>(&serialized).unwrap();
}

That... doesn't seem right to me. As far as I understand, if "$serde_json::private::Number" is the first key in a map, the deserializer expects its value to be a string, but otherwise just treats it as a normal key. Which seems... a bit unnecessarily magical, but the fact that the order of keys may be changed by the round-trip really pushes this more towards "there is a bug here" in my opinion. As far as I can tell everything here is intentional but it seems like this is quite the papercut.

Thoughts?


Also I'm just sitting here in awe that cargo-fuzz synthesized this example

@dtolnay
Copy link
Member

dtolnay commented Jan 22, 2022

Thanks for flagging. I think I'm fine sticking with this behavior. As you noted, all of the code involved is intentional.

@dtolnay dtolnay closed this as completed Jan 22, 2022
@serde-rs serde-rs locked and limited conversation to collaborators Mar 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants