Skip to content

Commit 259d8ac

Browse files
authored
MOD-14010 support Homogenues array floating point forcing(deserializa… (#17)
* MOD-13577 support Homogenues array floating point forcing(deserialization path only) * add fallback option * export FPHAConfig * docs * fmt * comments * lower fuzz time * bring back old code * change to lossy push * Binary encoder/decoder * remove fallback from FPHAConfig * more fuzz tests * tag to enum * update fuzz parameters in ci * fmt * remove print in fuzz * wrap with zstd compression * misc * move to cbor based implementation * . * fmt * CR * move to fork of ciborium * fix CR * fmt * misc: JsonValue in fuzz tests to use serde * fmt * revert to manual string in fuzz, fix push_with_fp case * cr * remove dead code * . * CR * move to arbitrary-json crate in fuzz tests
1 parent ad1001a commit 259d8ac

13 files changed

Lines changed: 987 additions & 93 deletions

File tree

.github/actions/fuzz_tests/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ inputs:
88
fuzz_time:
99
description: 'Maximum time in seconds to run fuzzing'
1010
required: false
11-
default: '180'
11+
default: '300'
1212
cargo_fuzz_version:
1313
description: 'Version of cargo-fuzz to install'
1414
required: false
@@ -26,5 +26,5 @@ runs:
2626
- name: Run Fuzz Tests
2727
shell: bash
2828
working-directory: fuzz
29-
run: cargo fuzz run ${{ inputs.fuzz_target }} --release -- -max_total_time=${{ inputs.fuzz_time }}
29+
run: cargo fuzz run ${{ inputs.fuzz_target }} --release -- -max_total_time=${{ inputs.fuzz_time }} -ignore_ooms=1 -rss_limit_mb=0
3030

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ jobs:
2424
matrix:
2525
fuzz_target:
2626
- fuzz_json_de
27-
# Add more fuzz targets here as needed
27+
- fuzz_cbor_decode
28+
- fuzz_cbor_roundtrip
2829
steps:
2930
- name: Checkout repository
3031
uses: actions/checkout@v4

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@ serde = { workspace = true }
3030
serde_json = { workspace = true }
3131
ctor = { version = "0.1.16", optional = true }
3232
paste = "1.0.15"
33-
half = "2.0.0"
33+
ciborium = { git = "https://github.com/AvivDavid23/ciborium", branch = "main" }
34+
ciborium-ll = { git = "https://github.com/AvivDavid23/ciborium", branch = "main" }
35+
bytemuck = "1"
36+
half = { version = "2.0.0", features = ["bytemuck"] }
37+
thiserror = "2.0.18"
38+
zstd = "0.13"
3439

3540
[dev-dependencies]
3641
mockalloc = "0.1.2"
3742
ctor = "0.1.16"
3843
rand = "0.8.4"
39-
44+
zstd = "0.13"

fuzz/Cargo.toml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ edition = "2021"
77
[package.metadata]
88
cargo-fuzz = true
99

10+
[lib]
11+
name = "ijson_fuzz"
12+
path = "src/lib.rs"
13+
1014
[dependencies]
1115
libfuzzer-sys = "0.4"
1216
arbitrary = { version = "1.3", features = ["derive"] }
13-
serde = { workspace = true }
17+
serde = { workspace = true, features = ["derive"] }
1418
serde_json = { workspace = true }
19+
arbitrary-json = "=0.1.1"
1520

1621
[dependencies.ijson]
1722
path = ".."
@@ -22,3 +27,17 @@ path = "fuzz_targets/fuzz_json_de.rs"
2227
test = false
2328
doc = false
2429
bench = false
30+
31+
[[bin]]
32+
name = "fuzz_cbor_decode"
33+
path = "fuzz_targets/fuzz_cbor_decode.rs"
34+
test = false
35+
doc = false
36+
bench = false
37+
38+
[[bin]]
39+
name = "fuzz_cbor_roundtrip"
40+
path = "fuzz_targets/fuzz_cbor_roundtrip.rs"
41+
test = false
42+
doc = false
43+
bench = false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![no_main]
2+
3+
use ijson::cbor::decode;
4+
use libfuzzer_sys::fuzz_target;
5+
6+
fuzz_target!(|data: &[u8]| {
7+
let _ = decode(data);
8+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![no_main]
2+
3+
use arbitrary_json::ArbitraryValue;
4+
use ijson::{cbor, IValue};
5+
use libfuzzer_sys::fuzz_target;
6+
use serde::Deserialize;
7+
8+
fuzz_target!(|value: ArbitraryValue| {
9+
let json_string = value.to_string();
10+
let mut deserializer = serde_json::Deserializer::from_str(&json_string);
11+
let Ok(original) = IValue::deserialize(&mut deserializer) else {
12+
return;
13+
};
14+
15+
let encoded = cbor::encode(&original);
16+
let decoded = cbor::decode(&encoded).expect("encode->decode round-trip must not fail");
17+
18+
assert_eq!(
19+
original, decoded,
20+
"round-trip mismatch for input: {json_string}"
21+
);
22+
});

fuzz/fuzz_targets/fuzz_json_de.rs

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,12 @@
11
#![no_main]
22

3-
use arbitrary::Arbitrary;
3+
use arbitrary_json::ArbitraryValue;
44
use ijson::IValue;
55
use libfuzzer_sys::fuzz_target;
66
use serde::Deserialize;
7-
use std::collections::HashMap;
87

9-
#[derive(Arbitrary, Debug)]
10-
enum JsonValue {
11-
Null,
12-
Bool(bool),
13-
Number(f64),
14-
String(String),
15-
Array(Vec<JsonValue>),
16-
Object(HashMap<String, JsonValue>),
17-
}
18-
19-
impl JsonValue {
20-
fn to_json_string(&self) -> String {
21-
match self {
22-
JsonValue::Null => "null".to_string(),
23-
JsonValue::Bool(b) => b.to_string(),
24-
JsonValue::Number(n) => {
25-
if n.is_finite() {
26-
n.to_string()
27-
} else {
28-
"0".to_string()
29-
}
30-
}
31-
JsonValue::String(s) => format!("\"{}\"", s),
32-
JsonValue::Array(arr) => {
33-
let items: Vec<String> = arr.iter().map(|v| v.to_json_string()).collect();
34-
format!("[{}]", items.join(","))
35-
}
36-
JsonValue::Object(obj) => {
37-
let items: Vec<String> = obj
38-
.iter()
39-
.map(|(k, v)| {
40-
let key = k.clone();
41-
format!("\"{}\":{}", key, v.to_json_string())
42-
})
43-
.collect();
44-
format!("{{{}}}", items.join(","))
45-
}
46-
}
47-
}
48-
}
49-
50-
fuzz_target!(|value: JsonValue| {
51-
let json_string = value.to_json_string();
8+
fuzz_target!(|value: ArbitraryValue| {
9+
let json_string = value.to_string();
5210
let mut deserializer = serde_json::Deserializer::from_str(&json_string);
5311
let _ = IValue::deserialize(&mut deserializer);
5412
});

fuzz/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)