Skip to content

Commit 4fbb7b9

Browse files
committed
bump 0.3.15
1 parent fe77809 commit 4fbb7b9

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "Apache-2.0"
1010
name = "sonic-rs"
1111
readme = "README.md"
1212
repository = "https://github.com/cloudwego/sonic-rs"
13-
version = "0.3.14"
13+
version = "0.3.15"
1414

1515
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1616

fuzz/fuzz_targets/from_slice.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#![no_main]
22
#![allow(clippy::mutable_key_type)]
3+
use std::{borrow::Cow, collections::HashMap, hash::Hash, marker::PhantomData};
34

5+
use faststr::FastStr;
46
use libfuzzer_sys::fuzz_target;
7+
use serde::{Deserialize, Serialize};
58
use serde_json::Value as JValue;
69
use sonic_rs::{
710
from_slice, from_str, to_array_iter, to_array_iter_unchecked, to_object_iter,
8-
to_object_iter_unchecked, value::JsonContainerTrait, JsonNumberTrait, JsonValueTrait, Value,
11+
to_object_iter_unchecked, value::JsonContainerTrait, Deserializer, JsonNumberTrait,
12+
JsonValueTrait, Value,
913
};
1014

1115
macro_rules! test_type {
@@ -54,8 +58,8 @@ fuzz_target!(|data: &[u8]| {
5458
let sv2: Value = from_str(&sout).unwrap();
5559
let eq = compare_value(&jv2, &sv2);
5660

57-
// compare use raw
5861
fuzz_use_raw(data, &sv);
62+
fuzz_utf8_lossy(data, &sv);
5963

6064
if jv.is_object() && eq {
6165
for ret in to_object_iter(data) {
@@ -119,7 +123,6 @@ fn compare_lazyvalue(jv: &JValue, sv: &sonic_rs::LazyValue) {
119123
}
120124

121125
fn fuzz_use_raw(json: &[u8], sv: &sonic_rs::Value) {
122-
use sonic_rs::{Deserialize, Deserializer, Value};
123126
let json = unsafe { std::str::from_utf8_unchecked(json) };
124127
let mut de = Deserializer::from_str(json).use_raw();
125128
let value: Value = Deserialize::deserialize(&mut de).unwrap();
@@ -128,6 +131,15 @@ fn fuzz_use_raw(json: &[u8], sv: &sonic_rs::Value) {
128131
assert_eq!(&got, sv);
129132
}
130133

134+
fn fuzz_utf8_lossy(json: &[u8], sv: &sonic_rs::Value) {
135+
let json = unsafe { std::str::from_utf8_unchecked(json) };
136+
let mut de = Deserializer::from_str(json).utf8_lossy();
137+
let value: Value = Deserialize::deserialize(&mut de).unwrap();
138+
let out = sonic_rs::to_string(&value).unwrap();
139+
let got: Value = sonic_rs::from_str(&out).unwrap();
140+
assert_eq!(&got, sv);
141+
}
142+
131143
fn compare_value(jv: &JValue, sv: &sonic_rs::Value) -> bool {
132144
match *jv {
133145
JValue::Object(ref obj) => {
@@ -175,11 +187,6 @@ fn compare_value(jv: &JValue, sv: &sonic_rs::Value) -> bool {
175187
true
176188
}
177189

178-
use std::{borrow::Cow, collections::HashMap, hash::Hash, marker::PhantomData};
179-
180-
use faststr::FastStr;
181-
use serde::{Deserialize, Serialize};
182-
183190
#[derive(Debug, Deserialize, Serialize, PartialEq)]
184191
struct Foo {
185192
name: FastStr,

scripts/fuzz.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ set -ex
44

55
cargo install cargo-fuzz
66

7-
RUST_BACKTRACE=full cargo +nightly fuzz run fuzz_value
7+
RUST_BACKTRACE=full cargo +nightly fuzz run fuzz_value -- -max_total_time=20m

src/serde/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'de, R: Reader<'de>> Deserializer<R> {
385385
// get n to check trailing characters in later
386386
let n = if cfg.utf8_lossy && self.parser.read.next_invalid_utf8() != usize::MAX {
387387
// repr the invalid utf8, not need to care about the invalid UTF8 char in non-string
388-
// parts, it will cause erros when parsing.
388+
// parts, it will cause errors when parsing.
389389
val.parse_with_padding(String::from_utf8_lossy(json).as_bytes(), cfg)?
390390
} else {
391391
val.parse_with_padding(json, cfg)?

0 commit comments

Comments
 (0)