File tree Expand file tree Collapse file tree 4 files changed +34
-2
lines changed
Expand file tree Collapse file tree 4 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 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;
313extern crate bson;
414use bson:: RawDocument ;
515
Original file line number Diff line number Diff line change 1+ //! Document serialization consistency
12#![ no_main]
23#[ macro_use]
34extern 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} ) ;
Original file line number Diff line number Diff line change 1+ //! Ensure correctness of UTF-8 and string parsing
12#![ no_main]
23#[ macro_use]
34extern crate libfuzzer_sys;
Original file line number Diff line number Diff line change 1+ //! BSON type marker validation
12#![ no_main]
23#[ macro_use]
34extern crate libfuzzer_sys;
You can’t perform that action at this time.
0 commit comments