Skip to content

Commit 623ae63

Browse files
authored
Merge changes from main (#398)
1 parent adf148a commit 623ae63

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/de/raw.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,16 @@ impl<'d, 'de> DocumentAccess<'d, 'de> {
511511
F: FnOnce(&mut Self) -> Result<O>,
512512
{
513513
let start_bytes = self.root_deserializer.bytes.bytes_read();
514-
let out = f(self);
514+
let out = f(self)?;
515515
let bytes_read = self.root_deserializer.bytes.bytes_read() - start_bytes;
516-
*self.length_remaining -= bytes_read as i32;
517-
518-
if *self.length_remaining < 0 {
516+
let bytes_read: i32 = bytes_read
517+
.try_into()
518+
.map_err(|_| Error::custom("overflow in read size"))?;
519+
if bytes_read > *self.length_remaining {
519520
return Err(Error::custom("length of document too short"));
520521
}
521-
out
522+
*self.length_remaining -= bytes_read;
523+
Ok(out)
522524
}
523525

524526
/// Read the next value from the document.

src/tests/serde.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,3 +1042,9 @@ fn oid_as_hex_string() {
10421042
let doc = to_document(&foo).unwrap();
10431043
assert_eq!(doc.get_str("oid").unwrap(), oid.to_hex());
10441044
}
1045+
1046+
#[test]
1047+
fn fuzz_regression_00() {
1048+
let buf: &[u8] = &[227, 0, 35, 4, 2, 0, 255, 255, 255, 127, 255, 255, 255, 47];
1049+
let _ = crate::from_slice::<Document>(buf);
1050+
}

0 commit comments

Comments
 (0)