Skip to content

Commit

Permalink
Devin comments added, asked Devin to verify that Serialization matche…
Browse files Browse the repository at this point in the history
…s original input, as well
  • Loading branch information
pmeredit committed Dec 11, 2024
1 parent 21c25e4 commit 17654e8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
12 changes: 11 additions & 1 deletion fuzz/fuzz_targets/malformed_length.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
//! BSON Document Length Field Fuzzer
//!
//! This fuzz test focuses on finding security vulnerabilities related to BSON document length
//! fields. It specifically targets:
//! - Integer overflow/underflow in length calculations
//! - Malformed length fields that could cause buffer overruns
//! - Mismatches between declared and actual document sizes
//! - Memory allocation issues with large or invalid lengths
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
#[macro_use]
extern crate libfuzzer_sys;
extern crate bson;
use bson::RawDocument;

Expand Down
22 changes: 21 additions & 1 deletion fuzz/fuzz_targets/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Document serialization consistency
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
Expand Down Expand Up @@ -48,6 +49,25 @@ fuzz_target!(|buf: &[u8]| {
}
}
}
let _ = doc_buf.into_bytes();
let output_bytes = doc_buf.into_bytes();
if let Ok(reserialized_doc) = RawDocument::from_bytes(&output_bytes) {
assert_eq!(doc.as_bytes().len(), reserialized_doc.as_bytes().len());
let orig_elements: Vec<_> = doc.iter_elements().flatten().collect();
let reser_elements: Vec<_> = reserialized_doc.iter_elements().flatten().collect();
assert_eq!(
orig_elements.len(),
reser_elements.len(),
"Document element count mismatch"
);
for (orig, reser) in orig_elements.iter().zip(reser_elements.iter()) {
assert_eq!(orig.key(), reser.key(), "Key mismatch");
assert_eq!(
orig.value(),
reser.value(),
"Value mismatch for key {}",
orig.key()
);
}
}
}
});
1 change: 1 addition & 0 deletions fuzz/fuzz_targets/string_handling.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Ensure correctness of UTF-8 and string parsing
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
Expand Down
1 change: 1 addition & 0 deletions fuzz/fuzz_targets/type_markers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! BSON type marker validation
#![no_main]
#[macro_use]
extern crate libfuzzer_sys;
Expand Down

0 comments on commit 17654e8

Please sign in to comment.