Skip to content

Commit e1d94ca

Browse files
committed
ll: fix oob read in parse_content_metadata() found by fuzz
1 parent 1c3854c commit e1d94ca

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/ll.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ pub fn parse_content_metadata(bytes: &[u8]) -> Result<(usize, Content), Error> {
105105
0 => Ok((1, Content::None)),
106106
1 => Err(Error::ContentMetadata),
107107
2 => {
108+
if bytes.len() < 3 {
109+
return Err(Error::ContentMetadata);
110+
}
108111
let bip_number = u16::from_be_bytes(bytes[1..3].try_into().expect("len ok"));
109112
match bip_number {
110113
380 => Ok((3, Content::Bip380)),
@@ -114,7 +117,7 @@ pub fn parse_content_metadata(bytes: &[u8]) -> Result<(usize, Content), Error> {
114117
}
115118
}
116119
len => {
117-
let end = (len + 1) as usize;
120+
let end = (len as usize + 1).min(bytes.len());
118121
let data = &bytes[1..end].to_vec();
119122
Ok((end, Content::Proprietary(data.to_vec())))
120123
}

0 commit comments

Comments
 (0)