Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BMFF: fix handling of boxes w/ zero length or type (backport #2612) #2614

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
// 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 @@
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