Skip to content

Commit

Permalink
Merge pull request #1981 from Exiv2/mergify/bp/0.27-maintenance/pr-1978
Browse files Browse the repository at this point in the history
Limit CR3 previews to JPEG only (backport #1978)
  • Loading branch information
clanmills committed Oct 21, 2021
2 parents 5bfb4d9 + 5b2fcf7 commit c42684f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/exiv2/bmffimage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ namespace Exiv2
void parseCr3Preview(DataBuf &data,
std::ostream &out,
bool bTrace,
uint8_t version,
uint32_t width_offset,
uint32_t height_offset,
uint32_t size_offset,
Expand Down
32 changes: 25 additions & 7 deletions src/bmffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,25 @@ namespace Exiv2
parseXmp(box_length,io_->tell());
break;
case TAG_thmb:
if (version == 0) {
parseCr3Preview(data, out, bTrace, skip, skip+2, skip+4, skip+12);
switch (version) {
case 0: // JPEG
parseCr3Preview(data, out, bTrace, version, skip, skip+2, skip+4, skip+12);
break;
case 1: // HDR
parseCr3Preview(data, out, bTrace, version, skip+2, skip+4, skip+8, skip+12);
break;
default:
break;
}
break;
case TAG_prvw:
if (version == 0) {
parseCr3Preview(data, out, bTrace, skip+2, skip+4, skip+8, skip+12);
switch (version) {
case 0: // JPEG
case 1: // HDR
parseCr3Preview(data, out, bTrace, version, skip+2, skip+4, skip+8, skip+12);
break;
default:
break;
}
break;

Expand Down Expand Up @@ -584,14 +596,13 @@ namespace Exiv2
void BmffImage::parseCr3Preview(DataBuf &data,
std::ostream& out,
bool bTrace,
uint8_t version,
uint32_t width_offset,
uint32_t height_offset,
uint32_t size_offset,
uint32_t relative_position)
{
// Derived from https://github.com/lclevy/canon_cr3
// Only JPEG (version 0) is currently supported
// (relative_position is identical between versions)
long here = io_->tell();
enforce(here >= 0 &&
here <= std::numeric_limits<long>::max() - static_cast<long>(relative_position),
Expand All @@ -606,7 +617,14 @@ namespace Exiv2
enforce(size_offset <= static_cast<size_t>(data.size_ - 4), kerCorruptedMetadata);
nativePreview.size_ = getLong(data.pData_ + size_offset, endian_);
nativePreview.filter_ = "";
nativePreview.mimeType_ = "image/jpeg";
switch (version) {
case 0:
nativePreview.mimeType_ = "image/jpeg";
break;
default:
nativePreview.mimeType_ = "application/octet-stream";
break;
}
nativePreviews_.push_back(nativePreview);

if (bTrace) {
Expand Down

0 comments on commit c42684f

Please sign in to comment.