From 44dd8a6ecf8514c576b3b1c9e009105b5d5bafa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbjo=CC=88rn=20Einarsson?= Date: Wed, 25 Jan 2023 22:43:23 +0100 Subject: [PATCH] version 0.33.2 - restore parsing behavior for non-complete mdat --- Versions.md | 1 + mp4/box.go | 2 +- mp4/boxsr.go | 10 ++++++++-- mp4/mdat.go | 5 ++++- mp4/version.go | 4 ++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Versions.md b/Versions.md index 578f83a3..a4f729ef 100644 --- a/Versions.md +++ b/Versions.md @@ -2,6 +2,7 @@ | Version | Highlights | | ------ | ---------- | +| 0.33.2 | Reset parsing of non-complete mdat box to previous behavior | | 0.33.1 | Fix parsing of HEVC SPS scaling list data present flag | | 0.33.0 | Support QuickTime meta box. New possibility to disable parsing of specific boxes | | 0.32.0 | Repo moved to github.com/Eyevinn/mp4ff | diff --git a/mp4/box.go b/mp4/box.go index fdb58dd5..a33322f5 100644 --- a/mp4/box.go +++ b/mp4/box.go @@ -362,7 +362,7 @@ func makebuf(b Box) []byte { return make([]byte, b.Size()-boxHeaderSize) } -// readBoxBody - read box body and check length +// readBoxBody reads complete box body. Returns error if not possible func readBoxBody(r io.Reader, h BoxHeader) ([]byte, error) { bodyLen := h.Size - uint64(h.Hdrlen) if bodyLen == 0 { diff --git a/mp4/boxsr.go b/mp4/boxsr.go index 49c2f6f4..e9b0ec34 100644 --- a/mp4/boxsr.go +++ b/mp4/boxsr.go @@ -138,8 +138,14 @@ func DecodeBoxSR(startPos uint64, sr bits.SliceReader) (Box, error) { if err != nil { return nil, err } - if h.Size > uint64(sr.NrRemainingBytes())+uint64(h.Hdrlen) { - return nil, fmt.Errorf("decode box %q, size %d too big", h.Name, h.Size) + + maxSize := uint64(sr.NrRemainingBytes()) + uint64(h.Hdrlen) + // In the following, we do not block mdat to allow for the case + // that the first kiloBytes of a file are fetched and parsed to + // get the init part of a file. In the future, a new decode option that + // stops before the mdat starts is a better alternative. + if h.Size > maxSize && h.Name != "mdat" { + return nil, fmt.Errorf("decode box %q, size %d too big (max %d)", h.Name, h.Size, maxSize) } d, ok := decodersSR[h.Name] diff --git a/mp4/mdat.go b/mp4/mdat.go index eb803458..8907ff8c 100644 --- a/mp4/mdat.go +++ b/mp4/mdat.go @@ -32,7 +32,10 @@ func DecodeMdat(hdr BoxHeader, startPos uint64, r io.Reader) (Box, error) { return &MdatBox{startPos, data, nil, 0, largeSize}, nil } -// DecodeMdatSR - box-specific decode +// DecodeMdatSR decodes an mdat box +// +// Currently no content and no error is returned if not full length available. +// If not enough content, an accumulated error is stored in sr, though func DecodeMdatSR(hdr BoxHeader, startPos uint64, sr bits.SliceReader) (Box, error) { largeSize := hdr.Hdrlen > boxHeaderSize return &MdatBox{startPos, sr.ReadBytes(hdr.payloadLen()), nil, 0, largeSize}, nil diff --git a/mp4/version.go b/mp4/version.go index a6ef1e5d..64346b1a 100644 --- a/mp4/version.go +++ b/mp4/version.go @@ -7,8 +7,8 @@ import ( ) var ( - commitVersion string = "v0.33.1" // May be updated using build flags - commitDate string = "1674662982" // commitDate in Epoch seconds (may be overridden using build flags) + commitVersion string = "v0.33.2" // May be updated using build flags + commitDate string = "1674682900" // commitDate in Epoch seconds (may be overridden using build flags) ) // GetVersion - get version and also commitHash and commitDate if inserted via Makefile