chore(pumpkin-nbt): add fuzzing & benches
This commit is contained in:
1 parent
60ad62bbf1
commit
35b91efd38
14 files changed
+647
-8
No files matched your search
@@ -0,0 +1,9 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin_nbt::nbt_compress::read_gzip_compound_tag;
|
||||
use std::io::Cursor;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let cursor = Cursor::new(data);
|
||||
let _ = read_gzip_compound_tag(cursor);
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin_nbt::Nbt;
|
||||
use pumpkin_nbt::deserializer::NbtReadHelper;
|
||||
use std::io::Cursor;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let mut cursor = Cursor::new(data);
|
||||
let mut reader = NbtReadHelper::new(&mut cursor);
|
||||
let _ = Nbt::read(&mut reader);
|
||||
|
||||
let mut cursor_unnamed = Cursor::new(data);
|
||||
let mut reader_unnamed = NbtReadHelper::new(&mut cursor_unnamed);
|
||||
let _ = Nbt::read_unnamed(&mut reader_unnamed);
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
#![no_main]
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin_nbt::deserializer::{from_bytes, from_bytes_unnamed};
|
||||
use serde::Deserialize;
|
||||
use std::io::Cursor;
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq)]
|
||||
struct FuzzStruct {
|
||||
byte: i8,
|
||||
short: i16,
|
||||
int: i32,
|
||||
long: i64,
|
||||
float: f32,
|
||||
double: f64,
|
||||
string: String,
|
||||
byte_array: Vec<u8>,
|
||||
int_array: Vec<i32>,
|
||||
long_array: Vec<i64>,
|
||||
list_string: Vec<String>,
|
||||
nested: Option<Box<FuzzStruct>>,
|
||||
}
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let cursor = Cursor::new(data);
|
||||
let _: Result<FuzzStruct, _> = from_bytes(cursor);
|
||||
|
||||
let cursor_unnamed = Cursor::new(data);
|
||||
let _: Result<FuzzStruct, _> = from_bytes_unnamed(cursor_unnamed);
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
#![no_main]
|
||||
use arbitrary::Arbitrary;
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use pumpkin_nbt::deserializer::from_bytes;
|
||||
use pumpkin_nbt::serializer::to_bytes;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::io::Cursor;
|
||||
|
||||
#[derive(Arbitrary, Serialize, Deserialize, Debug, PartialEq)]
|
||||
struct RoundtripStruct {
|
||||
byte: i8,
|
||||
short: i16,
|
||||
int: i32,
|
||||
long: i64,
|
||||
float: f32,
|
||||
double: f64,
|
||||
string: String,
|
||||
byte_array: Vec<u8>,
|
||||
int_array: Vec<i32>,
|
||||
long_array: Vec<i64>,
|
||||
list_string: Vec<String>,
|
||||
// Nested struct to test recursion
|
||||
nested: Option<Box<RoundtripStruct>>,
|
||||
}
|
||||
|
||||
fuzz_target!(|data: RoundtripStruct| {
|
||||
let mut bytes = Vec::new();
|
||||
if to_bytes(&data, &mut bytes).is_ok() {
|
||||
let cursor = Cursor::new(bytes);
|
||||
let reconstructed: RoundtripStruct = from_bytes(cursor).expect("Failed to deserialize valid NBT");
|
||||
assert_eq!(data, reconstructed);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user