Skip to content

Commit 7adc057

Browse files
committed
Return early from parser::block_data
This is to deal with issue #3 since it mostly has to do with the length of metdata blocks being larger than the buffer.
1 parent 1b44706 commit 7adc057

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/metadata/parser.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use nom::{
22
be_u8, be_u16, be_u32, be_u64,
33
le_u32,
4-
IResult,
4+
IResult, Needed,
55
ErrorKind, Err,
66
};
77

@@ -275,6 +275,14 @@ named!(pub header <&[u8], (bool, u8, u32)>,
275275

276276
pub fn block_data(input: &[u8], block_type: u8, length: u32)
277277
-> IResult<&[u8], metadata::Data> {
278+
let len = length as usize;
279+
280+
if len > input.len() {
281+
let needed = Needed::Size(len);
282+
283+
return IResult::Incomplete(needed);
284+
}
285+
278286
match block_type {
279287
0 => stream_info(input),
280288
1 => padding(input, length),

0 commit comments

Comments
 (0)