You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What version of MongoDB are you using? (Check with the MongoDB shell using db.version()) None
What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)? None
Describe the bug
Because BSON describes its own length, the from_slice and from_reader functions should be able to deserialize from a reader or slice that is larger than the BSON itself.
BE SPECIFIC:
What is the expected behavior and what is actually happening? Expected deserialization to consider the length encoded within the BSON itself.
Do you have any particular output that demonstrates this problem? Using to_vec followed by from_slice to serialize then deserialize a struct
Do you have any ideas on why this may be happening that could give us a
clue in the right direction?
Did this issue arise out of nowhere, or after an update (of the driver,
server, and/or Rust)? No
Are there multiple ways of triggering this bug (perhaps more than one
function produce a crash)?
If you know how to reproduce this bug, please include a code snippet here:
use bson;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct Foo {
a: i32,
b: Bar,
}
#[derive(Serialize, Deserialize, Debug)]
struct Bar {
x: u32,
y: String,
}
fn main() {
let data = Foo {
a: 42,
b: Bar {
x: 1,
y: "hello".to_string(),
},
};
let bson_bytes = bson::to_vec(&data).unwrap();
let mut bigger_buffer: Vec<u8> = vec![0; 1000];
bigger_buffer[..bson_bytes.len()].copy_from_slice(&bson_bytes);
println!("{:?}", bson::from_slice::<Foo>(bigger_buffer.as_slice()).unwrap());
}
The text was updated successfully, but these errors were encountered:
Just an update - we don't see this as high priority to implement since there's a clear workaround (subslice) and the validation that buffer length matches bson length is useful both for internal parsing and potentially for external users. Can you give more details on your use case?
Versions/Environment
cargo pkgid mongodb
&cargo pkgid bson
) registry+https://github.com/rust-lang/crates.io-index#[email protected]db.version()
) NoneDescribe the bug
Because BSON describes its own length, the
from_slice
andfrom_reader
functions should be able to deserialize from a reader or slice that is larger than the BSON itself.BE SPECIFIC:
to_vec
followed byfrom_slice
to serialize then deserialize a structclue in the right direction?
server, and/or Rust)? No
function produce a crash)?
The text was updated successfully, but these errors were encountered: