diff options
-rw-r--r-- | components/net/mime_classifier.rs | 4 | ||||
-rw-r--r-- | tests/unit/net/mime_classifier.rs | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/components/net/mime_classifier.rs b/components/net/mime_classifier.rs index fe844f82212..b1ee9231baf 100644 --- a/components/net/mime_classifier.rs +++ b/components/net/mime_classifier.rs @@ -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; } diff --git a/tests/unit/net/mime_classifier.rs b/tests/unit/net/mime_classifier.rs index 2ae03ef5369..bcc5b54066c 100644 --- a/tests/unit/net/mime_classifier.rs +++ b/tests/unit/net/mime_classifier.rs @@ -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, |