Skip to content

Instantly share code, notes, and snippets.

@adetaylor
Created March 4, 2022 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adetaylor/977fec82e5105ceeca4c26e0a85c34ed to your computer and use it in GitHub Desktop.
Save adetaylor/977fec82e5105ceeca4c26e0a85c34ed to your computer and use it in GitHub Desktop.
itoa fuzzer
#![no_main]
use libfuzzer_sys::fuzz_target;
use libfuzzer_sys::arbitrary;
#[derive(arbitrary::Arbitrary,Debug,Clone)]
enum IntegerInput {
I8(i8),
U8(u8),
I16(i16),
U16(u16),
I32(i32),
U32(u32),
I64(i64),
U64(u64),
ISIZE(isize),
USIZE(usize),
I128(i128),
U128(u128),
}
#[derive(arbitrary::Arbitrary,Debug,Clone)]
struct Inputs {
inputs: Vec<IntegerInput>
}
fuzz_target!(|input: Inputs| {
let mut buffer = itoa::Buffer::new();
for input_integer in input.inputs {
match input_integer {
IntegerInput::I8(val) => buffer.format(val),
IntegerInput::U8(val) => buffer.format(val),
IntegerInput::I16(val) => buffer.format(val),
IntegerInput::U16(val) => buffer.format(val),
IntegerInput::I32(val) => buffer.format(val),
IntegerInput::U32(val) => buffer.format(val),
IntegerInput::I64(val) => buffer.format(val),
IntegerInput::U64(val) => buffer.format(val),
IntegerInput::ISIZE(val) => buffer.format(val),
IntegerInput::USIZE(val) => buffer.format(val),
IntegerInput::I128(val) => buffer.format(val),
IntegerInput::U128(val) => buffer.format(val),
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment