Skip to content

Commit 51996a6

Browse files
committed
Limit CR3 previews to JPEG only
(cherry picked from commit 40e5021)
1 parent 2c8bdff commit 51996a6

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

include/exiv2/bmffimage.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ namespace Exiv2
121121
void parseCr3Preview(DataBuf &data,
122122
std::ostream &out,
123123
bool bTrace,
124-
uint16_t width_offset,
125-
uint16_t height_offset,
124+
uint32_t width_offset,
125+
uint32_t height_offset,
126126
uint32_t size_offset,
127-
uint16_t relative_position);
127+
uint32_t relative_position);
128128
//@}
129129

130130
//! @name Manipulators

src/bmffimage.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
#define TAG_cmt2 0x434D5432 /**< "CMD2" exifID */
7474
#define TAG_cmt3 0x434D5433 /**< "CMT3" canonID */
7575
#define TAG_cmt4 0x434D5434 /**< "CMT4" gpsID */
76-
#define TAG_colr 0x636f6c72 /**< "colr" */
76+
#define TAG_colr 0x636f6c72 /**< "colr" Colour information */
7777
#define TAG_exif 0x45786966 /**< "Exif" Used by JXL*/
78-
#define TAG_xml 0x786d6c20 /**< "xml " Used by JXL*/
78+
#define TAG_xml 0x786d6c20 /**< "xml " Used by JXL*/
7979
#define TAG_thmb 0x54484d42 /**< "THMB" Canon thumbnail */
8080
#define TAG_prvw 0x50525657 /**< "PRVW" Canon preview image */
8181

@@ -126,7 +126,7 @@ namespace Exiv2
126126

127127
bool BmffImage::fullBox(uint32_t box)
128128
{
129-
return box == TAG_meta || box == TAG_iinf || box == TAG_iloc;
129+
return box == TAG_meta || box == TAG_iinf || box == TAG_iloc || box == TAG_thmb || box == TAG_prvw;
130130
}
131131

132132
std::string BmffImage::mimeType() const
@@ -247,7 +247,7 @@ namespace Exiv2
247247
enforce(data.size_ - skip >= 4, Exiv2::kerCorruptedMetadata);
248248
flags = getLong(data.pData_ + skip, endian_); // version/flags
249249
version = static_cast<uint8_t>(flags >> 24);
250-
version &= 0x00ffffff;
250+
flags &= 0x00ffffff;
251251
skip += 4;
252252
}
253253

@@ -468,10 +468,14 @@ namespace Exiv2
468468
parseXmp(box_length,io_->tell());
469469
break;
470470
case TAG_thmb:
471-
parseCr3Preview(data, out, bTrace, 4, 6, 8, 16);
471+
if (version == 0) {
472+
parseCr3Preview(data, out, bTrace, skip, skip+2, skip+4, skip+12);
473+
}
472474
break;
473475
case TAG_prvw:
474-
parseCr3Preview(data, out, bTrace, 6, 8, 12, 16);
476+
if (version == 0) {
477+
parseCr3Preview(data, out, bTrace, skip+2, skip+4, skip+8, skip+12);
478+
}
475479
break;
476480

477481
default: break ; /* do nothing */
@@ -560,17 +564,19 @@ namespace Exiv2
560564
void BmffImage::parseCr3Preview(DataBuf &data,
561565
std::ostream& out,
562566
bool bTrace,
563-
uint16_t width_offset,
564-
uint16_t height_offset,
567+
uint32_t width_offset,
568+
uint32_t height_offset,
565569
uint32_t size_offset,
566-
uint16_t relative_position)
570+
uint32_t relative_position)
567571
{
568572
// Derived from https://github.com/lclevy/canon_cr3
569-
NativePreview nativePreview;
573+
// Only JPEG (version 0) is currently supported
574+
// (relative_position is identical between versions)
570575
long here = io_->tell();
571576
enforce(here >= 0 &&
572-
here <= std::numeric_limits<long>::max() - relative_position,
577+
here <= std::numeric_limits<long>::max() - static_cast<long>(relative_position),
573578
kerCorruptedMetadata);
579+
NativePreview nativePreview;
574580
nativePreview.position_ = here + relative_position;
575581
enforce(4 <= data.size_, kerCorruptedMetadata);
576582
enforce(width_offset <= static_cast<size_t>(data.size_ - 2), kerCorruptedMetadata);

0 commit comments

Comments
 (0)