Skip to content

Commit

Permalink
Calculate mp4 header length correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jongiddy committed Feb 12, 2016
1 parent a24e86e commit ec0ea46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/net/mime_classifier.rs
Expand Up @@ -325,8 +325,8 @@ impl Mp4Matcher {
return false;
}

let box_size = ((data[0] as u32) << 3 | (data[1] as u32) << 2 |
(data[2] as u32) << 1 | (data[3] as u32)) as usize;
let box_size = ((data[0] as u32) << 24 | (data[1] as u32) << 16 |
(data[2] as u32) << 8 | (data[3] as u32)) as usize;
if (data.len() < box_size) || (box_size % 4 != 0) {
return false;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/net/mime_classifier.rs
Expand Up @@ -37,6 +37,19 @@ fn test_sniff_mp4_matcher() {
}
}

#[test]
fn test_sniff_mp4_matcher_long() {
// Check that a multi-byte length is calculated correctly
let matcher = Mp4Matcher;

let mut data: [u8; 260] = [0; 260];
&data[.. 11].clone_from_slice(
&[0x00, 0x00, 0x01, 0x04, 0x66, 0x74, 0x79, 0x70, 0x6D, 0x70, 0x34]
);

assert!(matcher.matches(&data));
}

#[cfg(test)]
fn test_sniff_with_flags(filename_orig: &path::Path,
type_string: &str,
Expand Down

0 comments on commit ec0ea46

Please sign in to comment.