Skip to content

Commit 2dcd3d8

Browse files
authored
Merge pull request #336 from mozilla/permit-hdlr-nonzero-reserved
Allow `HandlerBox` (`hdlr`) non-zero values in `reserved` and `pre-defined` fields
2 parents c6ba5af + 9b60aa7 commit 2dcd3d8

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

mp4parse/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4410,8 +4410,9 @@ fn read_alac<T: Read>(src: &mut BMFFBox<T>) -> Result<ALACSpecificBox> {
44104410
Ok(ALACSpecificBox { version, data })
44114411
}
44124412

4413-
/// Parse a Handler Reference Box.
4414-
/// See ISOBMFF (ISO 14496-12:2020) § 8.4.3
4413+
/// Parse a Handler Reference Box.<br />
4414+
/// See ISOBMFF (ISO 14496-12:2020) § 8.4.3<br />
4415+
/// See [\[ISOBMFF\]: reserved (field = 0;) handling is ambiguous](https://github.com/MPEGGroup/FileFormat/issues/36)
44154416
fn read_hdlr<T: Read>(src: &mut BMFFBox<T>, strictness: ParseStrictness) -> Result<HandlerBox> {
44164417
if read_fullbox_version_no_flags(src)? != 0 {
44174418
return Err(Error::Unsupported("hdlr version"));
@@ -4420,7 +4421,7 @@ fn read_hdlr<T: Read>(src: &mut BMFFBox<T>, strictness: ParseStrictness) -> Resu
44204421
let pre_defined = be_u32(src)?;
44214422
if pre_defined != 0 {
44224423
fail_if(
4423-
strictness != ParseStrictness::Permissive,
4424+
strictness == ParseStrictness::Strict,
44244425
"The HandlerBox 'pre_defined' field shall be 0 \
44254426
per ISOBMFF (ISO 14496-12:2020) § 8.4.3.2",
44264427
)?;
@@ -4432,7 +4433,7 @@ fn read_hdlr<T: Read>(src: &mut BMFFBox<T>, strictness: ParseStrictness) -> Resu
44324433
let reserved = be_u32(src)?;
44334434
if reserved != 0 {
44344435
fail_if(
4435-
strictness != ParseStrictness::Permissive,
4436+
strictness == ParseStrictness::Strict,
44364437
"The HandlerBox 'reserved' fields shall be 0 \
44374438
per ISOBMFF (ISO 14496-12:2020) § 8.4.3.2",
44384439
)?;

mp4parse/src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ fn read_hdlr_invalid_pre_defined_field() {
515515
let mut stream = iter.next_box().unwrap().unwrap();
516516
assert_eq!(stream.head.name, BoxType::HandlerBox);
517517
assert_eq!(stream.head.size, 32);
518-
match super::read_hdlr(&mut stream, ParseStrictness::Normal) {
518+
match super::read_hdlr(&mut stream, ParseStrictness::Strict) {
519519
Err(Error::InvalidData(msg)) => assert_eq!(
520520
"The HandlerBox 'pre_defined' field shall be 0 \
521521
per ISOBMFF (ISO 14496-12:2020) § 8.4.3.2",
@@ -537,7 +537,7 @@ fn read_hdlr_invalid_reserved_field() {
537537
let mut stream = iter.next_box().unwrap().unwrap();
538538
assert_eq!(stream.head.name, BoxType::HandlerBox);
539539
assert_eq!(stream.head.size, 32);
540-
match super::read_hdlr(&mut stream, ParseStrictness::Normal) {
540+
match super::read_hdlr(&mut stream, ParseStrictness::Strict) {
541541
Err(Error::InvalidData(msg)) => assert_eq!(
542542
"The HandlerBox 'reserved' fields shall be 0 \
543543
per ISOBMFF (ISO 14496-12:2020) § 8.4.3.2",
294 Bytes
Binary file not shown.

mp4parse/tests/public.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static IMAGE_AVIF_IPMA_INVALID_PROPERTY_INDEX: &str =
4747
static IMAGE_AVIF_NO_HDLR: &str = "tests/corrupt/hdlr-not-first.avif";
4848
static IMAGE_AVIF_HDLR_NOT_FIRST: &str = "tests/corrupt/no-hdlr.avif";
4949
static IMAGE_AVIF_HDLR_NOT_PICT: &str = "tests/corrupt/hdlr-not-pict.avif";
50+
static IMAGE_AVIF_HDLR_NONZERO_RESERVED: &str = "tests/hdlr-nonzero-reserved.avif";
5051
static IMAGE_AVIF_NO_MIF1: &str = "tests/no-mif1.avif";
5152
static IMAGE_AVIF_NO_PIXI: &str = "tests/corrupt/no-pixi.avif";
5253
static IMAGE_AVIF_NO_AV1C: &str = "tests/corrupt/no-av1C.avif";
@@ -934,6 +935,15 @@ fn public_avif_hdlr_is_pict() {
934935
assert_avif_shall(IMAGE_AVIF_HDLR_NOT_PICT, expected_msg);
935936
}
936937

938+
#[test]
939+
fn public_avif_hdlr_nonzero_reserved() {
940+
let expected_msg = "The HandlerBox 'reserved' fields shall be 0 \
941+
per ISOBMFF (ISO 14496-12:2020) § 8.4.3.2";
942+
// This is a "should" despite the spec indicating a (somewhat ambiguous)
943+
// requirement that this field is set to zero.
944+
assert_avif_should(IMAGE_AVIF_HDLR_NONZERO_RESERVED, expected_msg);
945+
}
946+
937947
#[test]
938948
fn public_avif_no_mif1() {
939949
let expected_msg = "The FileTypeBox should contain 'mif1' in the compatible_brands list \

0 commit comments

Comments
 (0)