Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ jobs:
wasmtime run "$wasm_file"
done


test-nightly-hosted:
strategy:
fail-fast: false
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/riscv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: RISC-V CI

on: [push, pull_request]

permissions:
contents: read

env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-24.04-riscv
timeout-minutes: 45
steps:
- uses: actions/checkout@v6
- run: uname -m
- run: gcc --version
- uses: dtolnay/rust-toolchain@stable
- run: make
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: test

test:
./scripts/test.sh
26 changes: 18 additions & 8 deletions fuzz/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ impl NumberInput {
}

impl NumberPattern {
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
match self {
NumberPattern::Integer { negative, digits } => {
Expand Down Expand Up @@ -552,8 +553,8 @@ impl DeepNestInput {
}
NestPattern::Mixed { depth, width } => {
let d = (*depth).min(256) as usize;
let w = (*width).min(8) as usize;
let mut s = String::with_capacity(d * w * 8);
let w = (*width).clamp(1, 8) as usize;
let mut s = String::with_capacity(d * w * 12 + 16);
build_mixed(&mut s, d, w);
s
}
Expand All @@ -567,17 +568,26 @@ fn build_mixed(out: &mut String, depth: usize, width: usize) {
return;
}
out.push('[');
let recursive_index = depth % width;
for i in 0..width {
if i > 0 {
out.push(',');
}
if i % 2 == 0 {
build_mixed(out, depth - 1, width);
if i == recursive_index {
if depth & 1 == 0 {
build_mixed(out, depth - 1, width);
} else {
out.push_str("{\"v\":");
build_mixed(out, depth - 1, width);
out.push('}');
}
} else {
out.push('{');
write!(out, "\"v\":").unwrap();
build_mixed(out, depth - 1, width);
out.push('}');
match i % 4 {
0 => out.push_str("null"),
1 => write!(out, "{{\"v\":{}}}", depth).unwrap(),
2 => out.push_str("true"),
_ => write!(out, "\"s{}\"", depth).unwrap(),
}
}
}
out.push(']');
Expand Down
14 changes: 14 additions & 0 deletions fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,20 @@ mod test {
.unwrap();
}

#[test]
fn test_deep_mixed_generation_is_bounded() {
let input = gen::DeepNestInput {
pattern: gen::NestPattern::Mixed {
depth: 256,
width: 253,
},
};
let json = input.to_json();

assert!(json.len() < 32 * 1024, "json len: {}", json.len());
assert!(json.contains("{\"v\":["));
}

#[test]
fn test_fuzz_serde_roundtrip_raw_seeds() {
for seed in [
Expand Down
2 changes: 1 addition & 1 deletion src/lazyvalue/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'a> Debug for LazyValue<'a> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
.debug_struct("LazyValue")
.field("raw json", &format_args!("{}", &self.as_raw_str()))
.field("raw json", &format_args!("{}", self.as_raw_str()))
.field("has_escaped", &self.inner.status)
.finish()
}
Expand Down
16 changes: 8 additions & 8 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ where
// ---- find separator: one u16 read to match `,"` or `}x` ----
let sep = self.read.peek_u16();
// Little-endian: `,"` = 0x222C, `}x` = (x << 8) | 0x7D
if sep == u16::from_le_bytes([b',', b'"']) {
if sep == u16::from_le_bytes(*b",\"") {
self.read.eat(2);
continue;
}
Expand Down Expand Up @@ -1404,7 +1404,7 @@ where

#[inline(always)]
fn skip_number_unsafe(&mut self) -> Result<()> {
let _ = self.get_next_token([b']', b'}', b','], 0);
let _ = self.get_next_token(*b"]},", 0);
Ok(())
}

Expand Down Expand Up @@ -1640,7 +1640,7 @@ where
}

// deal with the empty object
match self.get_next_token([b'"', b'}'], 1) {
match self.get_next_token(*b"\"}", 1) {
Some(b'"') => {}
Some(b'}') => return perr!(self, GetInEmptyObject),
None => return perr!(self, EofWhileParsing),
Expand Down Expand Up @@ -1677,7 +1677,7 @@ where
_ => {}
};
// optimize: direct find the next quote of key or object ending
match self.get_next_token([b'"', b'}'], 1) {
match self.get_next_token(*b"\"}", 1) {
Some(b'"') => continue,
Some(b'}') => return perr!(self, GetUnknownKeyInObject),
None => return perr!(self, EofWhileParsing),
Expand Down Expand Up @@ -1733,7 +1733,7 @@ where
_ => {}
};
// optimize: direct find the next token
match self.get_next_token([b']', b','], 1) {
match self.get_next_token(*b"],", 1) {
Some(b']') => return perr!(self, GetIndexOutOfArray),
Some(b',') => {
count -= 1;
Expand Down Expand Up @@ -1841,7 +1841,7 @@ where
_ => return perr!(self, ExpectObjectKeyOrEnd),
}
} else {
match self.get_next_token([b'"', b'}'], 1) {
match self.get_next_token(*b"\"}", 1) {
Some(b'"') => {}
Some(b'}') => return perr!(self, GetInEmptyObject),
None => return perr!(self, EofWhileParsing),
Expand Down Expand Up @@ -1882,7 +1882,7 @@ where
}
} else {
// optimize: direct find the next quote of key. or object ending
match self.get_next_token([b'"', b'}'], 1) {
match self.get_next_token(*b"\"}", 1) {
Some(b'"') => {}
Some(b'}') => break,
None => return perr!(self, EofWhileParsing),
Expand Down Expand Up @@ -1964,7 +1964,7 @@ where
}
} else {
// optimize: direct find the next token
match self.get_next_token([b']', b','], 1) {
match self.get_next_token(*b"],", 1) {
Some(b']') => break,
Some(b',') => {
index += 1;
Expand Down
Loading