-
Notifications
You must be signed in to change notification settings - Fork 0
MOD-14010 support Homogenues array floating point forcing(deserializa… #17
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
base: master
Are you sure you want to change the base?
Changes from all commits
8e137e1
bfd678b
2079a68
cec89cf
bc60e68
931d520
3ba050f
8cd9ddf
3cfee7d
f166310
fa80dbe
6780eac
86e63be
746ac87
f3d275d
954fa38
8222832
4bfdfec
b6e1ac7
2a547e2
b40b8d8
043b76c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #![no_main] | ||
|
|
||
| use ijson::cbor::decode; | ||
| use libfuzzer_sys::fuzz_target; | ||
|
|
||
| fuzz_target!(|data: &[u8]| { | ||
| let _ = decode(data); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #![no_main] | ||
|
|
||
| use ijson::{cbor, IValue}; | ||
| use ijson_fuzz::JsonValue; | ||
| use libfuzzer_sys::fuzz_target; | ||
| use serde::Deserialize; | ||
|
|
||
| fuzz_target!(|value: JsonValue| { | ||
| let json_string = value.to_json_string(); | ||
| let mut deserializer = serde_json::Deserializer::from_str(&json_string); | ||
| let Ok(original) = IValue::deserialize(&mut deserializer) else { | ||
| return; | ||
| }; | ||
|
|
||
| let encoded = cbor::encode(&original); | ||
| let decoded = cbor::decode(&encoded).expect("encode->decode round-trip must not fail"); | ||
|
|
||
| assert_eq!( | ||
| original, decoded, | ||
| "round-trip mismatch for input: {json_string}" | ||
| ); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| use arbitrary::Arbitrary; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[derive(Debug, Arbitrary, Serialize, Deserialize)] | ||
| pub enum JsonValue { | ||
| Null, | ||
| Bool(bool), | ||
| Integer(u64), | ||
| Float(f64), | ||
| Str(String), | ||
| Array(Vec<JsonValue>), | ||
| Object(Vec<(String, JsonValue)>), | ||
| } | ||
|
|
||
| impl JsonValue { | ||
| pub fn to_json_string(&self) -> String { | ||
| match self { | ||
| JsonValue::Null => "null".to_string(), | ||
| JsonValue::Bool(b) => b.to_string(), | ||
| JsonValue::Integer(n) => n.to_string(), | ||
| JsonValue::Float(n) => { | ||
| if n.is_finite() { | ||
| n.to_string() | ||
| } else { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why infinite is converted to 0? |
||
| "0".to_string() | ||
| } | ||
| } | ||
| JsonValue::Str(s) => { | ||
| format!("\"{}\"", s.replace('\\', "\\\\").replace('"', "\\\"")) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use raw string literals when backslashes are involved (instead of the |
||
| } | ||
| JsonValue::Array(arr) => { | ||
| let items: Vec<String> = arr.iter().map(|v| v.to_json_string()).collect(); | ||
| format!("[{}]", items.join(",")) | ||
| } | ||
| JsonValue::Object(obj) => { | ||
| let items: Vec<String> = obj | ||
| .iter() | ||
| .map(|(k, v)| { | ||
| format!( | ||
| "\"{}\":{}", | ||
| k.replace('\\', "\\\\").replace('"', "\\\""), | ||
| v.to_json_string() | ||
| ) | ||
| }) | ||
| .collect(); | ||
| format!("{{{}}}", items.join(",")) | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.