Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat Exif.Sony1.PreviewImage as undefined tag (backport #2015) #2016

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,6 @@ namespace Exiv2 {
return;
}
p += 4;
uint32_t isize= 0; // size of Exif.Sony1.PreviewImage

if (count > std::numeric_limits<uint32_t>::max() / typeSize) {
throw Error(kerArithmeticOverflow);
Expand All @@ -1581,7 +1580,19 @@ namespace Exiv2 {
|| static_cast<int32_t>(baseOffset()) + offset <= 0)) {
// #1143
if ( object->tag() == 0x2001 && std::string(groupName(object->group())) == "Sony1" ) {
isize=size;
// This tag is Exif.Sony1.PreviewImage, which refers to a preview image which is
// not stored in the metadata. Instead it is stored at the end of the file, after
// the main image. The value of `size` refers to the size of the preview image, not
// the size of the tag's payload, so we set it to zero here so that we don't attempt
// to read those bytes from the metadata. We currently leave this tag as "undefined",
// although we may attempt to handle it better in the future. More discussion of
// this issue can be found here:
//
// https://github.com/Exiv2/exiv2/issues/2001
// https://github.com/Exiv2/exiv2/pull/2008
// https://github.com/Exiv2/exiv2/pull/2013
typeId = undefined;
size = 0;
} else {
#ifndef SUPPRESS_WARNINGS
EXV_ERROR << "Offset of directory " << groupName(object->group())
Expand Down Expand Up @@ -1629,20 +1640,7 @@ namespace Exiv2 {
}
Value::AutoPtr v = Value::create(typeId);
enforce(v.get() != NULL, kerCorruptedMetadata);
if ( !isize ) {
v->read(pData, size, byteOrder());
} else {
// Prevent large memory allocations: https://github.com/Exiv2/exiv2/issues/1881
enforce(isize <= 1024 * 1024, kerCorruptedMetadata);

// #1143 Write a "hollow" buffer for the preview image
// Sadly: we don't know the exact location of the image in the source (it's near offset)
// And neither TiffReader nor TiffEntryBase have access to the BasicIo object being processed
byte* buffer = (byte*) ::malloc(isize);
::memset(buffer,0,isize);
v->read(buffer,isize, byteOrder());
::free(buffer);
}
v->read(pData, size, byteOrder());

object->setValue(v);
object->setData(pData, size);
Expand Down
8 changes: 2 additions & 6 deletions tests/bugfixes/github/test_issue_1881.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@ class SonyPreviewImageLargeAllocation(metaclass=CaseMeta):
filename2 = path("$tmp_path/issue_1881_coverage.jpg")
commands = ["$exiv2 -q -d I rm $filename1", "$exiv2 -q -d I rm $filename2"]
stdout = ["",""]
stderr = [
"""Exiv2 exception in erase action for file $filename1:
$kerCorruptedMetadata
""",
""]
retval = [1,0]
stderr = ["",""]
retval = [0,0]