Skip to content

Commit

Permalink
make fuzz checks more lenient (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin authored Sep 9, 2024
1 parent eccf28e commit dd25fd0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ keywords = ["JSON", "parsing", "deserialization", "iter"]
categories = ["parser-implementations", "parsing"]
homepage = "https://github.com/pydantic/jiter/"
repository = "https://github.com/pydantic/jiter/"
rust-version = "1.73.0"
rust-version = "1.74.0"

[profile.bench]
debug = true
Expand Down
7 changes: 6 additions & 1 deletion crates/fuzz/fuzz_targets/compare_to_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ fn errors_equal(jiter_error: &JiterError, serde_error: &SerdeError, json_data: &
} else if matches!(jiter_error.error_type, JiterJsonErrorType::InvalidUnicodeCodePoint) {
// https://github.com/serde-rs/json/issues/1083
remove_suffix(&jiter_error_str) == remove_suffix(&serde_error_str)
} else if jiter_error_str.starts_with("invalid escape at line")
&& serde_error_str.starts_with("invalid escape at line")
{
// see fuzz failures on #130
true
} else {
return jiter_error_str == serde_error_str;
jiter_error_str == serde_error_str
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/jiter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ paste = "1.0.7"
serde_json = {version = "1.0.87", features = ["preserve_order", "arbitrary_precision", "float_roundtrip"]}
serde = "1.0.147"
pyo3 = { workspace = true, features = ["auto-initialize"] }
codspeed-bencher-compat = "2.3.1"
codspeed-bencher-compat = "2.7.1"

[build-dependencies]
pyo3-build-config = { workspace = true, optional = true }
Expand Down
10 changes: 10 additions & 0 deletions crates/jiter/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,16 @@ fn bad_high_order_string_tail() {
assert_eq!(e.description(&bytes), "invalid unicode code point at line 1 column 5")
}

#[test]
fn invalid_escape_position() {
// from fuzzing on #130
let bytes = br#""con(\u0trol character (\u000.00"#;
let e = JsonValue::parse(bytes, false).unwrap_err();
assert_eq!(e.error_type, JsonErrorType::InvalidEscape);
assert_eq!(e.index, 8);
assert_eq!(e.description(bytes), "invalid escape at line 1 column 9")
}

#[test]
fn simd_string_sizes() {
for i in 0..100 {
Expand Down

0 comments on commit dd25fd0

Please sign in to comment.