Skip to content

Commit 542b408

Browse files
committed
Permit multiple nuls in hdlr box name field.
`name` should be truncated after the first nul but we don't store the `name` field so this change just lifts the restriction on multiple nul bytes. Based on wording change drafted in MPEGGroup/FileFormat#35
1 parent eb0b625 commit 542b408

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

mp4parse/src/lib.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ pub enum Status {
203203
EsdsDecSpecificIntoTagQuantity,
204204
FtypBadSize,
205205
FtypNotFirst,
206-
HdlrNameMultipleNul,
207206
HdlrNameNoNul,
208207
HdlrNameNotUtf8,
209208
HdlrNotFirst,
@@ -525,11 +524,6 @@ impl From<Status> for &str {
525524
"The FileTypeBox shall be placed as early as possible in the file \
526525
per ISOBMFF (ISO 14496-12:2020) § 4.3.1"
527526
}
528-
Status::HdlrNameMultipleNul => {
529-
"The HandlerBox 'name' field shall have a NUL byte \
530-
only in the final position \
531-
per ISOBMFF (ISO 14496-12:2020) § 8.4.3.2"
532-
}
533527
Status::HdlrNameNoNul => {
534528
"The HandlerBox 'name' field shall be null-terminated \
535529
per ISOBMFF (ISO 14496-12:2020) § 8.4.3.2"
@@ -5522,21 +5516,14 @@ fn read_hdlr<T: Read>(src: &mut BMFFBox<T>, strictness: ParseStrictness) -> Resu
55225516

55235517
match std::str::from_utf8(src.read_into_try_vec()?.as_slice()) {
55245518
Ok(name) => {
5525-
match name.bytes().filter(|&b| b == b'\0').count() {
5526-
0 => fail_with_status_if(
5519+
match name.bytes().position(|b| b == b'\0') {
5520+
None => fail_with_status_if(
55275521
strictness != ParseStrictness::Permissive,
55285522
Status::HdlrNameNoNul,
55295523
)?,
5530-
1 => (),
5531-
n =>
5524+
// `name` must be nul-terminated and any trailing bytes after the first nul ignored.
55325525
// See https://github.com/MPEGGroup/FileFormat/issues/35
5533-
{
5534-
error!("Found {} nul bytes in {:x?}", n, name);
5535-
fail_with_status_if(
5536-
strictness == ParseStrictness::Strict,
5537-
Status::HdlrNameMultipleNul,
5538-
)?
5539-
}
5526+
Some(_) => (),
55405527
}
55415528
}
55425529
Err(_) => fail_with_status_if(

mp4parse/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ fn read_hdlr_multiple_nul_in_name() {
491491
assert_eq!(stream.head.size, 45);
492492
assert_eq!(
493493
super::Status::from(super::read_hdlr(&mut stream, ParseStrictness::Strict)),
494-
super::Status::HdlrNameMultipleNul,
494+
super::Status::Ok,
495495
);
496496
}
497497

mp4parse/tests/public.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ fn public_avif_hdlr_multiple_nul() {
10511051
// This is a "should" despite the spec indicating a (somewhat ambiguous)
10521052
// requirement about extra data in boxes
10531053
// See comments in read_hdlr
1054-
assert_avif_should(IMAGE_AVIF_HDLR_MULTIPLE_NUL, Status::HdlrNameMultipleNul);
1054+
assert_avif_should(IMAGE_AVIF_HDLR_MULTIPLE_NUL, Status::Ok);
10551055
}
10561056

10571057
#[test]

0 commit comments

Comments
 (0)