Skip to content

Commit 467bcd1

Browse files
committed
Remove unused string reading from read_hdlr and read_video_sample_entry.
We never store the fields anywhere (and probably never will), so there's no point keeping this code around.
1 parent b78dc3e commit 467bcd1

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
@@ -1648,8 +1648,8 @@ fn read_hdlr<T: Read>(src: &mut BMFFBox<T>) -> Result<HandlerBox> {
16481648
// Skip uninteresting fields.
16491649
skip(src, 12)?;
16501650

1651-
let bytes_left = src.bytes_left();
1652-
let _name = read_null_terminated_string(src, bytes_left)?;
1651+
// Skip name.
1652+
skip_box_remain(src)?;
16531653

16541654
Ok(HandlerBox {
16551655
handler_type: handler_type,
@@ -1679,12 +1679,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<(CodecType,
16791679
let height = be_u16(src)?;
16801680

16811681
// Skip uninteresting fields.
1682-
skip(src, 14)?;
1683-
1684-
let _compressorname = read_fixed_length_pascal_string(src, 32)?;
1685-
1686-
// Skip uninteresting fields.
1687-
skip(src, 4)?;
1682+
skip(src, 50)?;
16881683

16891684
// Skip clap/pasp/etc. for now.
16901685
let mut codec_specific = None;
@@ -2001,43 +1996,6 @@ fn read_buf<T: ReadBytesExt>(src: &mut T, size: usize) -> Result<Vec<u8>> {
20011996
Ok(buf)
20021997
}
20031998

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

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)