Bug #1360

exiv2 can't read metadata from tiff file (tiff directory length is too large)

Added by T Modes over 3 years ago. Updated over 3 years ago.

tiff parser
Target version:
Start date:
16 Jul 2018
Due date:
% Done:


Estimated time:
1.00 h


I currently experiment with RAW conversion and stumbled about a strange issue in exiv2 (using as exiv2 as library, but also reproducible with the exiv2 command line tool):

RAW file from Panasonic (.rw2 file): exiv2 reads fine.
JPG file converted from this RAW file (inclusive metadata): exiv2 reads fine.
TIFF file converted from the same RAW file (also inclusive metadata): exiv2 can't read any metadata:

exiv2.exe test.tif
Exiv2 exception in print action for file test.tif:
tiff directory length is too large

(tiffinfo, exiftool and image viewer have no problem with this file.)

I will attach a small test file which shows the error.

I tracked it down to the makernotes. When I remove the makernotes in the TIFF file with exiftool, exiv2 can read the file again.

Ideally exiv2 should also read the makernotes also from the TIFF (because it works fine for JPEG).
Or as a workaround would it possible to skip the makernotes tag and issue a warning only instead of an exception and skipping the whole file?


test.tif (8.59 KB) test.tif T Modes, 16 Jul 2018 18:49



Updated by Robin Mills over 3 years ago

  • Category set to tiff parser
  • Status changed from New to Assigned
  • Assignee set to Robin Mills
  • Target version set to 0.27
  • % Done changed from 0 to 50
  • Estimated time set to 1.00 h

Thanks for bringing this to your attention. And thank you for providing such a clear explanation of your situation.

Good News. I have a fix.

In v0.26, I added 10 lines of code to Exiv2 that I wish I had not added. I'd like you to remove 4 lines and I think you'll be happy.

diff --git a/src/rw2image.cpp b/src/rw2image.cpp
index c252fba0..6b3ec444 100644
--- a/src/rw2image.cpp
+++ b/src/rw2image.cpp
@@ -126,8 +126,8 @@ namespace Exiv2 {
             throw Error(kerNotAnImage, "RW2");
-        std::ofstream devnull;
-        printStructure(devnull, kpsRecursive, 0);
+        //std::ofstream devnull;
+        //printStructure(devnull, kpsRecursive, 0);
         ByteOrder bo = Rw2Parser::decode(exifData_,
diff --git a/src/tiffimage.cpp b/src/tiffimage.cpp
index c256b904..efcdda67 100644
--- a/src/tiffimage.cpp
+++ b/src/tiffimage.cpp
@@ -183,8 +183,8 @@ namespace Exiv2 {

         // recursively print the structure to /dev/null to ensure all metadata is in memory
         // must be recursive to handle NEFs which stores the raw image in a subIFDs
-        std::ofstream devnull;
-        printStructure(devnull,kpsRecursive);
+        //std::ofstream devnull;
+        //printStructure(devnull,kpsRecursive);
         ByteOrder bo = TiffParser::decode(exifData_,
Let me know how that works for you and I'll give you more explanation tomorrow.

Updated by T Modes over 3 years ago

Thanks for the fast feedback. I can confirm: with your patch it works fine for me.


Updated by Robin Mills over 3 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 50 to 100

Thanks for the update. I've known about the issues introduced by this for about one year. However, fixing this in 'master' causes the test harness changes involving binary files. Those changes cause 'master' to bloat (become fat). We're rewriting the test suite for v0.27.

For sure the changes above (and similar in cr2image.cpp, crwimage.cpp and orfimage.cpp) will be included in v0.27

502 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2 $ grep -l devnull src/*.cpp
503 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2 $ 

Also available in: Atom PDF