Skip to content

Commit

Permalink
BMFF: fix handling of boxes w/ zero length or type (backport #2612)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmilos committed May 11, 2023
1 parent 0ae4963 commit 8e14663
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 @@ -134,7 +134,7 @@ namespace Exiv2
// 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 @@ -238,6 +238,11 @@ namespace Exiv2
box_length = getULongLong(data.pData_, endian_);
}

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

Check warning on line 243 in src/bmffimage.cpp

View check run for this annotation

Codecov / codecov/patch

src/bmffimage.cpp#L243

Added line #L243 was not covered by tests
}

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

0 comments on commit 8e14663

Please sign in to comment.