Skip to content

Commit

Permalink
Return early from parser::block_data
Browse files Browse the repository at this point in the history
This is to deal with issue #3 since it mostly has to do with the length of
metdata blocks being larger than the buffer.
  • Loading branch information
sourrust committed Feb 5, 2016
1 parent 1b44706 commit 7adc057
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/metadata/parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use nom::{
be_u8, be_u16, be_u32, be_u64,
le_u32,
IResult,
IResult, Needed,
ErrorKind, Err,
};

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

pub fn block_data(input: &[u8], block_type: u8, length: u32)
-> IResult<&[u8], metadata::Data> {
let len = length as usize;

if len > input.len() {
let needed = Needed::Size(len);

return IResult::Incomplete(needed);
}

match block_type {
0 => stream_info(input),
1 => padding(input, length),
Expand Down

0 comments on commit 7adc057

Please sign in to comment.