-
Notifications
You must be signed in to change notification settings - Fork 4
test: switch from roundtrip based tests to e2e based fuzzers #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CommanderStorm
merged 16 commits into
fast-pack:main
from
CommanderStorm:better-rust-fuzzing
Feb 14, 2026
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a3e2faa
add an unified API
CommanderStorm ca25b50
make error handling more robust
CommanderStorm 5848a0a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4682eab
increase test coverage
CommanderStorm bdac88b
simplify typs
CommanderStorm a83d7af
refactor rust fuzzer to be oracle based
CommanderStorm 0b7f0a9
make fuzzing more actionable
CommanderStorm 8995af0
reduce some slop
CommanderStorm 367f12f
fix fmt
CommanderStorm 8fd5a99
fix clippy
CommanderStorm 0dee229
Update fuzz/fuzz_targets/cpp_roundtrip.rs
CommanderStorm 63a280c
Update fuzz/fuzz_targets/rust_decompress_oracle.rs
CommanderStorm ad0e8ed
deduplicate some logic
CommanderStorm 7e55018
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b7b5011
Update fuzz/README.md
CommanderStorm a3a7f28
Merge branch 'main' into better-rust-fuzzing
CommanderStorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| use fastpfor::cpp; | ||
| use fastpfor::rust; | ||
|
|
||
| pub type BoxedCppCodec = Box<dyn cpp::Codec32>; | ||
|
|
||
| #[derive(arbitrary::Arbitrary)] | ||
| pub struct FuzzInput<C> { | ||
| pub data: Vec<u32>, | ||
| pub codec: C, | ||
| } | ||
|
|
||
| impl<C: std::fmt::Debug> std::fmt::Debug for FuzzInput<C> { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| f.debug_struct("FuzzInput<C>") | ||
| .field("data_length", &self.data.len()) | ||
| .field("codec", &self.codec) | ||
| .finish() | ||
| } | ||
| } | ||
|
|
||
| #[derive(arbitrary::Arbitrary, Clone, Copy, PartialEq, Eq, Debug)] | ||
| pub enum RustCodec { | ||
| FastPFOR256, | ||
| FastPFOR128, | ||
| VariableByte, | ||
| JustCopy, | ||
| } | ||
|
|
||
| impl From<RustCodec> for rust::Codec { | ||
| fn from(codec: RustCodec) -> Self { | ||
| use rust::*; | ||
| match codec { | ||
| RustCodec::FastPFOR256 => Codec::from(FastPFOR::new(DEFAULT_PAGE_SIZE, BLOCK_SIZE_256)), | ||
| RustCodec::FastPFOR128 => Codec::from(FastPFOR::new(DEFAULT_PAGE_SIZE, BLOCK_SIZE_128)), | ||
| RustCodec::VariableByte => Codec::from(VariableByte::new()), | ||
| RustCodec::JustCopy => Codec::from(JustCopy::new()), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Copy, Eq, PartialEq, arbitrary::Arbitrary, Debug)] | ||
| pub enum CppCodec { | ||
| BP32, | ||
| Copy, | ||
| FastBinaryPacking8, | ||
| FastPFor128, | ||
| FastPFor256, | ||
| FastBinaryPacking16, | ||
| FastBinaryPacking32, | ||
| MaskedVByte, | ||
| NewPFor, | ||
| OptPFor, | ||
| PFor2008, | ||
| PFor, | ||
| SimdBinaryPacking, | ||
| SimdFastPFor128, | ||
| SimdFastPFor256, | ||
| SimdGroupSimple, | ||
| SimdGroupSimpleRingBuf, | ||
| SimdNewPFor, | ||
| SimdOptPFor, | ||
| SimdPFor, | ||
| SimdSimplePFor, | ||
| // Simple16, // cannot encode arbitrary bytes | ||
| // Simple8b, // cannot encode arbitrary bytes | ||
| // Simple8bRle, // cannot encode arbitrary bytes | ||
| // Simple9, // cannot encode arbitrary bytes | ||
| // Simple9Rle, // cannot encode arbitrary bytes | ||
| // SimplePFor, // cannot encode arbitrary bytes | ||
| // Snappy, // Conditional with #ifdef | ||
| StreamVByte, | ||
| VByte, | ||
| VarInt, | ||
| // VarIntG8iu, // Conditional with #ifdef | ||
| VarIntGb, | ||
| // VsEncoding, // This is leaking memory | ||
| } | ||
|
|
||
| impl From<CppCodec> for BoxedCppCodec { | ||
| fn from(codec: CppCodec) -> Self { | ||
| use cpp::*; | ||
| match codec { | ||
| CppCodec::BP32 => Box::new(BP32Codec::default()), | ||
| CppCodec::Copy => Box::new(CopyCodec::default()), | ||
| CppCodec::FastBinaryPacking8 => Box::new(FastBinaryPacking8Codec::default()), | ||
| CppCodec::FastPFor128 => Box::new(FastPFor128Codec::default()), | ||
| CppCodec::FastPFor256 => Box::new(FastPFor256Codec::default()), | ||
| CppCodec::FastBinaryPacking16 => Box::new(FastBinaryPacking16Codec::default()), | ||
| CppCodec::FastBinaryPacking32 => Box::new(FastBinaryPacking32Codec::default()), | ||
| CppCodec::MaskedVByte => Box::new(MaskedVByteCodec::default()), | ||
| CppCodec::NewPFor => Box::new(NewPForCodec::default()), | ||
| CppCodec::OptPFor => Box::new(OptPForCodec::default()), | ||
| CppCodec::PFor2008 => Box::new(PFor2008Codec::default()), | ||
| CppCodec::PFor => Box::new(PForCodec::default()), | ||
| CppCodec::SimdBinaryPacking => Box::new(SimdBinaryPackingCodec::default()), | ||
| CppCodec::SimdFastPFor128 => Box::new(SimdFastPFor128Codec::default()), | ||
| CppCodec::SimdFastPFor256 => Box::new(SimdFastPFor256Codec::default()), | ||
| CppCodec::SimdGroupSimple => Box::new(SimdGroupSimpleCodec::default()), | ||
| CppCodec::SimdGroupSimpleRingBuf => Box::new(SimdGroupSimpleRingBufCodec::default()), | ||
| CppCodec::SimdNewPFor => Box::new(SimdNewPForCodec::default()), | ||
| CppCodec::SimdOptPFor => Box::new(SimdOptPForCodec::default()), | ||
| CppCodec::SimdPFor => Box::new(SimdPForCodec::default()), | ||
| CppCodec::SimdSimplePFor => Box::new(SimdSimplePForCodec::default()), | ||
| // CppCodec::Simple16 => Box::new(Simple16Codec::default()), | ||
| // CppCodec::Simple8b => Box::new(Simple8bCodec::default()), | ||
| // CppCodec::Simple8bRle => Box::new(Simple8bRleCodec::default()), | ||
| // CppCodec::Simple9 => Box::new(Simple9Codec::default()), | ||
| // CppCodec::Simple9Rle => Box::new(Simple9RleCodec::default()), | ||
| // CppCodec::SimplePFor => Box::new(SimplePForCodec::default()), | ||
| // CppCodec::Snappy => Box::new(SnappyCodec::default()), | ||
| CppCodec::StreamVByte => Box::new(StreamVByteCodec::default()), | ||
| CppCodec::VByte => Box::new(VByteCodec::default()), | ||
| CppCodec::VarInt => Box::new(VarIntCodec::default()), | ||
| // CppCodec::VarIntG8iu => Box::new(VarIntG8iuCodec::default()), | ||
| CppCodec::VarIntGb => Box::new(VarIntGbCodec::default()), | ||
| // CppCodec::VsEncoding => Box::new(VsEncodingCodec::default()), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #![no_main] | ||
|
|
||
| use libfuzzer_sys::fuzz_target; | ||
| mod common; | ||
| use common::*; | ||
|
|
||
| fuzz_target!(|data: FuzzInput<CppCodec>| { | ||
| let codec = BoxedCppCodec::from(data.codec); | ||
| let input = data.data; | ||
|
|
||
| // Allocate output buffer with generous size | ||
| let mut output = vec![0u32; input.len() * 2 + 1024]; | ||
|
|
||
| // Compress the data | ||
| let enc_slice = codec.encode32(&input, &mut output).unwrap(); | ||
|
|
||
| // Now decompress | ||
| let mut decoded = vec![0u32; input.len() * 2 + 1024]; | ||
| let dec_slice = codec.decode32(enc_slice, &mut decoded).unwrap(); | ||
|
|
||
| // Verify roundtrip | ||
| if dec_slice.len() + input.len() < 200 { | ||
| assert_eq!(input, dec_slice, "Decompressed output mismatches"); | ||
| } else { | ||
| assert_eq!(dec_slice.len(), input.len(), "Decompressed length mismatch"); | ||
| for (i, (&original, &decoded)) in input.iter().zip(dec_slice.iter()).enumerate() { | ||
| assert_eq!( | ||
| original, decoded, | ||
| "Mismatch at position {i}: expected {original}, got {decoded}" | ||
| ); | ||
| } | ||
| } | ||
|
CommanderStorm marked this conversation as resolved.
|
||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.