Skip to content

Commit

Permalink
Check if embedded RAF image is really a TIFF (backport #1796) (#1851)
Browse files Browse the repository at this point in the history
* Check if embedded RAF image is really a TIFF

(cherry picked from commit be12ae6)

* Clarify comment on old vs new RAF

Co-authored-by: Christoph Hasse <[email protected]>
(cherry picked from commit 30f39ac)

* Check I/O read result on RAF inspection

Co-authored-by: Kevin Backhouse <[email protected]>
(cherry picked from commit 09de8dc)

* Add test

(cherry picked from commit 9c3db7f)

Co-authored-by: Miloš Komarčević <[email protected]>
Co-authored-by: Miloš Komarčević <[email protected]>
  • Loading branch information
3 people authored Aug 6, 2021
1 parent cca3e07 commit 66259b1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/rafimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file added test/data/issue_1791_new.raf
Binary file not shown.
Binary file added test/data/issue_1791_old.raf
Binary file not shown.
24 changes: 24 additions & 0 deletions tests/bugfixes/github/test_issue_1791.py
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 66259b1

Please sign in to comment.