Exiv2 / exiv2

Image metadata library and tools
http://www.exiv2.org/
Other
932 stars 281 forks source link

Failure to Export Due to Size or Unrecognized Tag #401

Closed clthomas closed 6 years ago

clthomas commented 6 years ago

Running exiv2 ex -e e on the attached image fails. I'm not sure what the problem is, the output is:

Warning: Exif tag Exif.PentaxDng.0x0406 not encoded
Warning: Exif tag Exif.PentaxDng.0x0406 not encoded
./IMG_1587.exv: Could not write metadata to file: Size of Exif JPEG segment is larger than 65535 bytes

but printing with exiv2 pr -pv does not produce an error and the output is less than 65535 bytes (13333) and I assume it is stored more efficiently in the file. The folks with digiKam thought the PentaxDng tag mentioned in the warning needed to be added to a blacklist. I tried with the ubuntu package 0.25-3.1ubuntu0.18.04.1 and building from the 0.26 branch and master and found the same problem.

If it is just that the size of exif data is larger than 65535 then this may be a duplicate of #396, but it may still be good to blacklist the tag that produces the warning.

img_1587

clanmills commented 6 years ago

Thanks for reporting this and providing a test file. As you've reported, printing the data is OK:

904 rmills@rmillsmbp:~/Downloads $ exiv2 -pa --grep original/i 44069984-08b86b76-9f47-11e8-993a-28204d67c49a.JPG 
Exif.Photo.DateTimeOriginal                  Ascii      20  2018:07:27 10:35:32
905 rmills@rmillsmbp:~/Downloads $ 

However extracting the metadata to an exv file is unhappy:

902 rmills@rmillsmbp:~/Downloads $ exiv2 -ee --verbose 44069984-08b86b76-9f47-11e8-993a-28204d67c49a.JPG 
File 1/1: 44069984-08b86b76-9f47-11e8-993a-28204d67c49a.JPG
Writing Exif data from 44069984-08b86b76-9f47-11e8-993a-28204d67c49a.JPG to ./44069984-08b86b76-9f47-11e8-993a-28204d67c49a.exv
Warning: Exif tag Exif.PentaxDng.0x0406 not encoded
Warning: Exif tag Exif.PentaxDng.0x0406 not encoded
Segmentation fault: 11
903 rmills@rmillsmbp:~/Downloads $ 

I'm on vacation at the moment and hope to investigate with the debugger in the next few days.

clanmills commented 6 years ago

Good News. This isn't related to #396. It's a simple bug in 10 year old code. It's amazing this has never been spotted and reported:

996 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2 $ git diff
diff --git a/src/exif.cpp b/src/exif.cpp
index 42d79471..985fad44 100644
--- a/src/exif.cpp
+++ b/src/exif.cpp
@@ -790,10 +790,10 @@ namespace Exiv2 {
             }
         }

-        // Delete unknown tags larger than 4kB and known tags larger than 40kB.
-        for (ExifData::iterator tag_iter = ed.begin(); pos != ed.end(); ) {
+        // Delete unknown tags larger than 4kB and known tags larger than 20kB.
+        for (ExifData::iterator tag_iter = ed.begin(); tag_iter != ed.end(); ) {
             if (   (tag_iter->size() > 4096 && tag_iter->tagName().substr(0, 2) == "0x")
-                || tag_iter->size() > 40960) {
+                ||  tag_iter->size() > 20*1024) {
 #ifndef SUPPRESS_WARNINGS
                 EXV_WARNING << "Exif tag " << tag_iter->key() << " not encoded\n";
 #endif
997 rmills@rmillsmbp:~/gnu/github/exiv2/exiv2 $ 

Let me know how this works for you, then I'll submit a PR to include this in the code-base.

clthomas commented 6 years ago

It works, thank you.

clanmills commented 6 years ago

Thanks for the feedback. I'll submit the PR, and close this issue, when I get home from vacation.

piponazo commented 6 years ago

I'll submit this patch for you @clanmills

clanmills commented 6 years ago

Thanks, Luis. I've copied the test file to the buildserver: http://exiv2.dyndns.org:8080/userContent/testfiles/401/poc.jpg