Skip to content

Commit 012fd66

Browse files
authored
Merge pull request #86 from kinetiknz/read_null_terminated_string
Remove unused string reading from read_hdlr and read_video_sample_entry.
2 parents 23f4cd0 + e06eae6 commit 012fd66

File tree

2 files changed

+3
-73
lines changed

2 files changed

+3
-73
lines changed

mp4parse/src/lib.rs

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,8 @@ fn read_hdlr<T: Read>(src: &mut BMFFBox<T>) -> Result<HandlerBox> {
16451645
// Skip uninteresting fields.
16461646
skip(src, 12)?;
16471647

1648-
let bytes_left = src.bytes_left();
1649-
let _name = read_null_terminated_string(src, bytes_left)?;
1648+
// Skip name.
1649+
skip_box_remain(src)?;
16501650

16511651
Ok(HandlerBox {
16521652
handler_type: handler_type,
@@ -1676,12 +1676,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<(CodecType,
16761676
let height = be_u16(src)?;
16771677

16781678
// Skip uninteresting fields.
1679-
skip(src, 14)?;
1680-
1681-
let _compressorname = read_fixed_length_pascal_string(src, 32)?;
1682-
1683-
// Skip uninteresting fields.
1684-
skip(src, 4)?;
1679+
skip(src, 50)?;
16851680

16861681
// Skip clap/pasp/etc. for now.
16871682
let mut codec_specific = None;
@@ -1998,43 +1993,6 @@ fn read_buf<T: ReadBytesExt>(src: &mut T, size: usize) -> Result<Vec<u8>> {
19981993
Ok(buf)
19991994
}
20001995

2001-
// TODO(kinetik): Find a copy of ISO/IEC 14496-1 to confirm various string encodings.
2002-
// XXX(kinetik): definition of "null-terminated" string is fuzzy, we have:
2003-
// - zero or more byte strings, with a single null terminating the string.
2004-
// - zero byte strings with no null terminator (i.e. zero space in the box for the string)
2005-
// - length-prefixed strings with no null terminator (e.g. bear_rotate_0.mp4)
2006-
// - multiple byte strings where more than one byte is a null.
2007-
fn read_null_terminated_string<T: ReadBytesExt>(src: &mut T, mut size: usize) -> Result<String> {
2008-
let mut buf = Vec::new();
2009-
while size > 0 {
2010-
let c = src.read_u8()?;
2011-
size -= 1;
2012-
if c == 0 {
2013-
break;
2014-
}
2015-
buf.push(c);
2016-
}
2017-
skip(src, size)?;
2018-
String::from_utf8(buf).map_err(From::from)
2019-
}
2020-
2021-
#[allow(dead_code)]
2022-
fn read_pascal_string<T: ReadBytesExt>(src: &mut T) -> Result<String> {
2023-
let len = src.read_u8()?;
2024-
let buf = read_buf(src, len as usize)?;
2025-
String::from_utf8(buf).map_err(From::from)
2026-
}
2027-
2028-
// Weird string encoding with a length prefix and a fixed sized buffer which
2029-
// contains padding if the string doesn't fill the buffer.
2030-
fn read_fixed_length_pascal_string<T: Read>(src: &mut T, size: usize) -> Result<String> {
2031-
assert!(size > 0);
2032-
let len = cmp::min(src.read_u8()? as usize, size - 1);
2033-
let buf = read_buf(src, len)?;
2034-
skip(src, size - 1 - buf.len())?;
2035-
String::from_utf8(buf).map_err(From::from)
2036-
}
2037-
20381996
fn be_i16<T: ReadBytesExt>(src: &mut T) -> Result<i16> {
20391997
src.read_i16::<byteorder::BigEndian>().map_err(From::from)
20401998
}

mp4parse/src/tests.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -741,18 +741,6 @@ fn read_edts_bogus() {
741741
}
742742
}
743743

744-
#[test]
745-
fn invalid_pascal_string() {
746-
// String claims to be 32 bytes long (we provide 33 bytes to account for
747-
// the 1 byte length prefix).
748-
let pstr = "\x20xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
749-
let mut stream = Cursor::new(pstr);
750-
// Reader wants to limit the total read length to 32 bytes, so any
751-
// returned string must be no longer than 31 bytes.
752-
let s = super::read_fixed_length_pascal_string(&mut stream, 32).unwrap();
753-
assert_eq!(s.len(), 31);
754-
}
755-
756744
#[test]
757745
fn skip_padding_in_boxes() {
758746
// Padding data could be added in the end of these boxes. Parser needs to skip
@@ -882,22 +870,6 @@ fn read_esds() {
882870
assert_eq!(es.decoder_specific_data, aac_dc_descriptor);
883871
}
884872

885-
#[test]
886-
fn read_null_terminated_string() {
887-
let tests = vec![
888-
vec![0u8], // Short null-terminated string.
889-
vec![65u8, 0u8], // Normal null-terminated string.
890-
vec![], // Empty string (no data).
891-
vec![4u8, 65u8, 66u8, 67u8, 68u8], // Length-prefixed string, not null-terminated.
892-
vec![0u8, 0u8], // Doubly null-terminated string.
893-
];
894-
for v in tests.iter() {
895-
let mut c = Cursor::new(v);
896-
super::read_null_terminated_string(&mut c, v.len()).expect("string read failed");
897-
assert_eq!(c.position(), v.len() as u64);
898-
}
899-
}
900-
901873
#[test]
902874
fn read_f4v_stsd() {
903875
let mut stream = make_box(BoxSize::Auto, b".mp3", |s| {

0 commit comments

Comments
 (0)