Skip to content

Commit 17654e8

Browse files
committed
Devin comments added, asked Devin to verify that Serialization matches original input, as well
1 parent 21c25e4 commit 17654e8

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

fuzz/fuzz_targets/malformed_length.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
//! BSON Document Length Field Fuzzer
2+
//!
3+
//! This fuzz test focuses on finding security vulnerabilities related to BSON document length
4+
//! fields. It specifically targets:
5+
//! - Integer overflow/underflow in length calculations
6+
//! - Malformed length fields that could cause buffer overruns
7+
//! - Mismatches between declared and actual document sizes
8+
//! - Memory allocation issues with large or invalid lengths
9+
110
#![no_main]
2-
#[macro_use] extern crate libfuzzer_sys;
11+
#[macro_use]
12+
extern crate libfuzzer_sys;
313
extern crate bson;
414
use bson::RawDocument;
515

fuzz/fuzz_targets/serialization.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Document serialization consistency
12
#![no_main]
23
#[macro_use]
34
extern crate libfuzzer_sys;
@@ -48,6 +49,25 @@ fuzz_target!(|buf: &[u8]| {
4849
}
4950
}
5051
}
51-
let _ = doc_buf.into_bytes();
52+
let output_bytes = doc_buf.into_bytes();
53+
if let Ok(reserialized_doc) = RawDocument::from_bytes(&output_bytes) {
54+
assert_eq!(doc.as_bytes().len(), reserialized_doc.as_bytes().len());
55+
let orig_elements: Vec<_> = doc.iter_elements().flatten().collect();
56+
let reser_elements: Vec<_> = reserialized_doc.iter_elements().flatten().collect();
57+
assert_eq!(
58+
orig_elements.len(),
59+
reser_elements.len(),
60+
"Document element count mismatch"
61+
);
62+
for (orig, reser) in orig_elements.iter().zip(reser_elements.iter()) {
63+
assert_eq!(orig.key(), reser.key(), "Key mismatch");
64+
assert_eq!(
65+
orig.value(),
66+
reser.value(),
67+
"Value mismatch for key {}",
68+
orig.key()
69+
);
70+
}
71+
}
5272
}
5373
});

fuzz/fuzz_targets/string_handling.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Ensure correctness of UTF-8 and string parsing
12
#![no_main]
23
#[macro_use]
34
extern crate libfuzzer_sys;

fuzz/fuzz_targets/type_markers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! BSON type marker validation
12
#![no_main]
23
#[macro_use]
34
extern crate libfuzzer_sys;

0 commit comments

Comments
 (0)