Skip to content

Commit 4a945c8

Browse files
committed
fix fuzz
1 parent 06c59ef commit 4a945c8

File tree

11 files changed

+51
-38
lines changed

11 files changed

+51
-38
lines changed

fuzz/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
target
33
corpus
44
artifacts
5+
Cargo.lock

fuzz/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ cargo-fuzz = true
1010

1111
[dependencies.bson]
1212
path = ".."
13+
features = ["serde"]
1314

1415
[dependencies.libfuzzer-sys]
1516
version = "0.4.0"
@@ -32,12 +33,12 @@ name = "iterate"
3233
path = "fuzz_targets/iterate.rs"
3334

3435
[[bin]]
35-
name = "raw_decode"
36-
path = "fuzz_targets/raw_decode.rs"
36+
name = "raw_deserialize"
37+
path = "fuzz_targets/raw_deserialize.rs"
3738

3839
[[bin]]
39-
name = "raw_decode_utf8_lossy"
40-
path = "fuzz_targets/raw_decode_utf8_lossy.rs"
40+
name = "raw_deserialize_utf8_lossy"
41+
path = "fuzz_targets/raw_deserialize_utf8_lossy.rs"
4142

4243
[[bin]]
4344
name = "type_markers"

fuzz/fuzz_targets/decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use bson::Document;
77
use std::io::Cursor;
88

99
fuzz_target!(|buf: &[u8]| {
10-
if let Ok(doc) = Document::from_reader(&mut Cursor::new(&buf[..])) {
10+
if let Ok(doc) = Document::decode_from_reader(&mut Cursor::new(&buf[..])) {
1111
let mut vec = Vec::with_capacity(buf.len());
12-
let _ = doc.to_writer(&mut vec);
12+
let _ = doc.encode_to_writer(&mut vec);
1313
}
1414
});

fuzz/fuzz_targets/iterate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate bson;
55
use bson::RawDocument;
66

77
fuzz_target!(|buf: &[u8]| {
8-
if let Ok(doc) = RawDocument::from_bytes(buf) {
8+
if let Ok(doc) = RawDocument::decode_from_bytes(buf) {
99
for _ in doc {}
1010
}
1111
});

fuzz/fuzz_targets/raw_decode.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

fuzz/fuzz_targets/raw_decode_utf8_lossy.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![no_main]
2+
#[macro_use]
3+
extern crate libfuzzer_sys;
4+
extern crate bson;
5+
use bson::Document;
6+
7+
fuzz_target!(|buf: &[u8]| {
8+
if let Ok(doc) = bson::deserialize_from_slice::<Document>(buf) {
9+
let _ = bson::serialize_to_vec(&doc);
10+
}
11+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![no_main]
2+
#[macro_use]
3+
extern crate libfuzzer_sys;
4+
extern crate bson;
5+
use bson::{serde_helpers::Utf8LossyDeserialization, Document};
6+
7+
fuzz_target!(|buf: &[u8]| {
8+
if let Ok(doc) = bson::deserialize_from_slice::<Utf8LossyDeserialization<Document>>(buf) {
9+
let _ = bson::serialize_to_vec(&doc.0);
10+
}
11+
});

fuzz/fuzz_targets/string_handling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bson::{RawBsonRef, RawDocument};
66
use std::convert::TryInto;
77

88
fuzz_target!(|buf: &[u8]| {
9-
if let Ok(doc) = RawDocument::from_bytes(buf) {
9+
if let Ok(doc) = RawDocument::decode_from_bytes(buf) {
1010
for elem in doc.iter_elements().flatten() {
1111
// Convert to RawBsonRef and check string-related types
1212
if let Ok(bson) = elem.try_into() {

fuzz/fuzz_targets/type_markers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bson::{RawBsonRef, RawDocument};
66
use std::convert::TryInto;
77

88
fuzz_target!(|buf: &[u8]| {
9-
if let Ok(doc) = RawDocument::from_bytes(buf) {
9+
if let Ok(doc) = RawDocument::decode_from_bytes(buf) {
1010
for elem in doc.iter_elements().flatten() {
1111
let _: Result<RawBsonRef, _> = elem.try_into();
1212
}

0 commit comments

Comments
 (0)