Skip to content

Commit

Permalink
BMFF: fix handling of boxes w/ zero length or type
Browse files Browse the repository at this point in the history
  • Loading branch information
kmilos committed May 10, 2023
1 parent 54700c4 commit 5dbb275
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static bool skipBox(uint32_t box) {
// Allows boxHandler() to optimise the reading of files by identifying
// box types that we're not interested in. Box types listed here must
// not appear in the cases in switch (box_type) in boxHandler().
return box == TAG_mdat; // mdat is where the main image lives and can be huge
return box == 0 || box == TAG_mdat; // mdat is where the main image lives and can be huge
}

std::string BmffImage::mimeType() const {
Expand Down Expand Up @@ -277,6 +277,11 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
box_length = data.read_uint64(0, endian_);
}

if (box_length == 0) {
// Zero length is also valid and indicates box extends to the end of file.
box_length = pbox_end - address;
}

// read data in box and restore file position
const size_t restore = io_->tell();
Internal::enforce(box_length >= hdrsize, Exiv2::ErrorCode::kerCorruptedMetadata);
Expand Down

0 comments on commit 5dbb275

Please sign in to comment.