Throw exception if the recursion goes too deep.

main
Kevin Backhouse 1 year ago
parent 99ee18cef7
commit 9d69a71670
No known key found for this signature in database
GPG Key ID: 9DD01852EE40366E

@ -56,7 +56,7 @@ class EXIV2API BmffImage : public Image {
@param create Specifies if an existing image should be read (false) @param create Specifies if an existing image should be read (false)
or if a new file should be created (true). 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);
//@} //@}
//@{ //@{
@ -138,6 +138,7 @@ class EXIV2API BmffImage : public Image {
uint16_t xmpID_{0}; uint16_t xmpID_{0};
std::map<uint32_t, Iloc> ilocs_; std::map<uint32_t, Iloc> ilocs_;
bool bReadMetadata_{false}; bool bReadMetadata_{false};
const size_t max_box_depth_;
//@} //@}
/*! /*!

@ -86,8 +86,8 @@ std::string Iloc::toString() const {
return Internal::stringFormat("ID = %u from,length = %u,%u", ID_, start_, length_); return Internal::stringFormat("ID = %u from,length = %u,%u", ID_, start_, length_);
} }
BmffImage::BmffImage(BasicIo::UniquePtr io, bool /* create */) : BmffImage::BmffImage(BasicIo::UniquePtr io, bool /* create */, size_t max_box_depth) :
Image(ImageType::bmff, mdExif | mdIptc | mdXmp, std::move(io)) { Image(ImageType::bmff, mdExif | mdIptc | mdXmp, std::move(io)), max_box_depth_(max_box_depth) {
} // BmffImage::BmffImage } // BmffImage::BmffImage
std::string BmffImage::toAscii(uint32_t n) { std::string BmffImage::toAscii(uint32_t n) {
@ -247,7 +247,7 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS
// never visit a box twice! // never visit a box twice!
if (depth == 0) if (depth == 0)
visits_.clear(); 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); throw Error(ErrorCode::kerCorruptedMetadata);
} }
visits_.insert(address); visits_.insert(address);

Loading…
Cancel
Save