Skip to content

Commit

Permalink
Throw exception if the recursion goes too deep.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse committed Feb 12, 2024
1 parent 99ee18c commit 9d69a71
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/exiv2/bmffimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class EXIV2API BmffImage : public Image {
@param create Specifies if an existing image should be read (false)
or if a new file should be created (true).
*/
BmffImage(BasicIo::UniquePtr io, bool create);
BmffImage(BasicIo::UniquePtr io, bool create, size_t max_box_depth = 1000);
//@}

//@{
Expand Down Expand Up @@ -138,6 +138,7 @@ class EXIV2API BmffImage : public Image {
uint16_t xmpID_{0};
std::map<uint32_t, Iloc> ilocs_;
bool bReadMetadata_{false};
const size_t max_box_depth_;
//@}

/*!
Expand Down
6 changes: 3 additions & 3 deletions src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ std::string Iloc::toString() const {
return Internal::stringFormat("ID = %u from,length = %u,%u", ID_, start_, length_);
}

BmffImage::BmffImage(BasicIo::UniquePtr io, bool /* create */) :
Image(ImageType::bmff, mdExif | mdIptc | mdXmp, std::move(io)) {
BmffImage::BmffImage(BasicIo::UniquePtr io, bool /* create */, size_t max_box_depth) :
Image(ImageType::bmff, mdExif | mdIptc | mdXmp, std::move(io)), max_box_depth_(max_box_depth) {
} // BmffImage::BmffImage

std::string BmffImage::toAscii(uint32_t n) {
Expand Down Expand Up @@ -247,7 +247,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
// never visit a box twice!
if (depth == 0)
visits_.clear();
if (visits_.find(address) != visits_.end() || visits_.size() > visits_max_) {
if (visits_.find(address) != visits_.end() || visits_.size() > visits_max_ || depth >= max_box_depth_) {
throw Error(ErrorCode::kerCorruptedMetadata);
}
visits_.insert(address);
Expand Down

0 comments on commit 9d69a71

Please sign in to comment.