Check if embedded RAF image is really a TIFF (backport #1796) (#1851)

* Check if embedded RAF image is really a TIFF

(cherry picked from commit be12ae6f9e2f053bf101902865deadfe7c937f8d)

* Clarify comment on old vs new RAF

Co-authored-by: Christoph Hasse <hassec@users.noreply.github.com>
(cherry picked from commit 30f39ac98c1671547aa0b4021081e374864f1f04)

* Check I/O read result on RAF inspection

Co-authored-by: Kevin Backhouse <kevinbackhouse@github.com>
(cherry picked from commit 09de8dc901a38555151bd87d89ada3bd931451ea)

* Add test

(cherry picked from commit 9c3db7f3c3cb48fe0669061e627174402f366816)

Co-authored-by: Miloš Komarčević <miloskomarcevic@aim.com>
Co-authored-by: Miloš Komarčević <4973094+kmilos@users.noreply.github.com>
main
mergify[bot] 4 years ago committed by GitHub
parent cca3e0766d
commit 66259b1c71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -349,17 +349,27 @@ namespace Exiv2 {
// sanity check. Does tiff lie inside the file?
enforce(Safe::add(tiffOffset, tiffLength) <= io_->size(), kerCorruptedMetadata);
DataBuf tiff(tiffLength);
if (io_->seek(tiffOffset, BasicIo::beg) != 0) throw Error(kerFailedToReadImageData);
io_->read(tiff.pData_, tiff.size_);
if (!io_->error() && !io_->eof())
// Check if this really is a tiff and then call the tiff parser.
// Check is needed because some older models just embed a raw bitstream.
// For those files we skip the parsing step.
if (io_->read(readBuff, 4) != 4) { throw Error(kerFailedToReadImageData); }
io_->seek(-4, BasicIo::cur);
if (memcmp(readBuff, "\x49\x49\x2A\x00", 4) == 0 ||
memcmp(readBuff, "\x4D\x4D\x00\x2A", 4) == 0)
{
TiffParser::decode(exifData_,
iptcData_,
xmpData_,
tiff.pData_,
tiff.size_);
DataBuf tiff(tiffLength);
io_->read(tiff.pData_, tiff.size_);
if (!io_->error() && !io_->eof())
{
TiffParser::decode(exifData_,
iptcData_,
xmpData_,
tiff.pData_,
tiff.size_);
}
}
} // RafImage::readMetadata

Binary file not shown.

Binary file not shown.

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from system_tests import CaseMeta, path
class RafNoTiffRegression(metaclass=CaseMeta):
"""
Regression test for the bug described in:
https://github.com/Exiv2/exiv2/issues/1791
"""
url = "https://github.com/Exiv2/exiv2/issues/1791"
filename1 = path("$data_path/issue_1791_old.raf")
filename2 = path("$data_path/issue_1791_new.raf")
commands = ["$exiv2 -pa $filename1", "$exiv2 -pa $filename2"]
stdout = ["""Exif.Image2.JPEGInterchangeFormat Long 1 104
Exif.Image2.JPEGInterchangeFormatLength Long 1 12
""",
"""Exif.Image2.JPEGInterchangeFormat Long 1 104
Exif.Image2.JPEGInterchangeFormatLength Long 1 12
Exif.Image.NewSubfileType Long 1 Primary image
"""]
stderr = ["", ""]
retval = [0, 0]
Loading…
Cancel
Save