@@ -127,6 +127,14 @@ namespace Exiv2
127
127
return box == TAG_meta || box == TAG_iinf || box == TAG_iloc;
128
128
}
129
129
130
+ static bool skipBox (uint32_t box)
131
+ {
132
+ // Allows boxHandler() to optimise the reading of files by identifying
133
+ // box types that we're not interested in. Box types listed here must
134
+ // not appear in the cases in switch (box_type) in boxHandler().
135
+ return box == TAG_mdat; // mdat is where the main image lives and can be huge
136
+ }
137
+
130
138
std::string BmffImage::mimeType () const
131
139
{
132
140
switch (fileType_) {
@@ -232,7 +240,18 @@ namespace Exiv2
232
240
long restore = io_->tell ();
233
241
enforce (box_length >= hdrsize, Exiv2::kerCorruptedMetadata);
234
242
enforce (box_length - hdrsize <= static_cast <size_t >(pbox_end - restore), Exiv2::kerCorruptedMetadata);
235
- DataBuf data (static_cast <long >(box_length - hdrsize));
243
+
244
+ const long buffer_size = static_cast <long >(box_length - hdrsize);
245
+ if (skipBox (box_type)) {
246
+ if (bTrace) {
247
+ out << std::endl;
248
+ }
249
+ // The enforce() above checks that restore + buffer_size won't
250
+ // exceed pbox_end, and by implication, won't excced LONG_MAX
251
+ return restore + buffer_size;
252
+ }
253
+
254
+ DataBuf data (buffer_size);
236
255
const long box_end = restore + data.size_ ;
237
256
io_->read (data.pData_ , data.size_ );
238
257
io_->seek (restore, BasicIo::beg);
@@ -250,6 +269,7 @@ namespace Exiv2
250
269
}
251
270
252
271
switch (box_type) {
272
+ // See notes in skipBox()
253
273
case TAG_ftyp: {
254
274
enforce (data.size_ >= 4 , Exiv2::kerCorruptedMetadata);
255
275
fileType_ = getLong (data.pData_ , endian_);
0 commit comments