From bd676bedc6e9cab6508c243af4d17910ea70f876 Mon Sep 17 00:00:00 2001 From: postscript-dev Date: Sun, 26 Sep 2021 15:29:03 +0100 Subject: [PATCH 1/2] Fix `exiv2 -pR` for Sony images (#1805) `exiv2 -pR` failed to process Sony makernotes. Fix checks if makernotes header has Sony string, then uses correct offset. Fix supplied by @clanmills --- src/image.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/image.cpp b/src/image.cpp index db6f7a9d4b..0ba1c25ce4 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -490,7 +490,11 @@ namespace Exiv2 { seekOrThrow(io, offset, BasicIo::beg, kerCorruptedMetadata); // position readOrThrow(io, bytes, jump, kerCorruptedMetadata) ; // read bytes[jump]=0 ; - if ( ::strcmp("Nikon",chars) == 0 ) { + + bool bNikon = ::strcmp("Nikon" ,chars) == 0; + bool bSony = ::strcmp("SONY DSC ",chars) == 0; + + if ( bNikon ) { // tag is an embedded tiff const long byteslen = count-jump; DataBuf bytes(byteslen); // allocate a buffer @@ -499,8 +503,9 @@ namespace Exiv2 { printTiffStructure(memIo,out,option,depth); } else { // tag is an IFD + uint32_t punt = bSony ? 12 : 0 ; seekOrThrow(io, 0, BasicIo::beg, kerCorruptedMetadata); // position - printIFDStructure(io,out,option,offset,bSwap,c,depth); + printIFDStructure(io,out,option,offset+punt,bSwap,c,depth); } seekOrThrow(io, restore, BasicIo::beg, kerCorruptedMetadata); // restore From 15353573c86b42eb48d7a0db48a74108f0d590ca Mon Sep 17 00:00:00 2001 From: postscript-dev Date: Sun, 26 Sep 2021 15:30:58 +0100 Subject: [PATCH 2/2] Regression test for #1805 --- tests/bugfixes/github/test_issue_1805.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/bugfixes/github/test_issue_1805.py diff --git a/tests/bugfixes/github/test_issue_1805.py b/tests/bugfixes/github/test_issue_1805.py new file mode 100644 index 0000000000..12ac83014b --- /dev/null +++ b/tests/bugfixes/github/test_issue_1805.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +import unittest +import system_tests +from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors + +# Check that `exiv2 -pr` works for different file types. +# ExifTool has a list of markers that appear in the headers: +# https://exiftool.org/makernote_types.html + +@unittest.skip("Skipping test using option -pR (only for Debug mode)") +class exiv2pRHeaderTest(metaclass=CaseMeta): + + url = "https://github.com/Exiv2/exiv2/issues/1805" + + filename = system_tests.path("$data_path/exiv2-SonyDSC-HX60V.exv") # Uses marker: "SONY DSC " + commands = ["$exiv2 -pR " + filename] + + stderr = [""] + retval = [0] + + compare_stdout = check_no_ASAN_UBSAN_errors \ No newline at end of file