xor-gate/goexif2

Decode failure: failed to read IFD tag count: EOF

rubenv opened this issue · 4 comments

Hi, I'm currently piping my entire photo library through goexif2 and I'm running into a decode failure with the following file: https://cloud.savanne.be/apps/gallery/s/bve5feag756seDj

exif: decode failed (tiff: failed to read IFD tag count: EOF)

Exiftool does manage to decode it correctly, so it must be some kind of known bug or unhandled case.

Will look into this further later on, but pointers on how to debug this further are definitely welcome.

In some very distant past, I used to write the metadata parsing code of taglib-sharp.

I ran the image above through the debug utilities from that one which yielded the following:

Tags in object  : TiffIFD, XMP

Comment         : 
Keywords        : 2007-09-10 Extreme Blue Expo + London Extreme Blue 
Rating          : 
DateTime        : 9/12/2007 4:12:32 PM
Orientation     : TopLeft
Software        : 
ExposureTime    : 0.00625
FNumber         : 10
ISOSpeedRatings : 800
FocalLength     : 48
FocalLength35mm : 
Make            : Canon
Model           : Canon EOS 350D DIGITAL
Width           : 3091
Height          : 2057
Type            : JFIF File

Writable?       : False
Corrupt?        : True
    * Impossibly large item count
    * Invalid IFD offset

So this file has known quirks. I'll have a look at how they're detect and how we can work around them in goexif2.

Also interesting: we have a little tool that strips image data from files. This allows you to make super-tiny JPEG files for unit tests. Over here: https://github.com/mono/taglib-sharp/blob/master/examples/StripImageData.cs

First one:

            if (count > 0x10000000) {
                // Some Nikon files are known to exhibit this corruption (or "feature").
                file.MarkAsCorrupt ("Impossibly large item count");
                return null;
            }

Happens while parsing the IFD.


Second one:

            if (base_offset + offset > length) {
                file.MarkAsCorrupt ("Invalid IFD offset");
                return 0;
            }

So there might be a pointer pointing outside of the image file.

PR submitted (#13), turned out to be an IFD offset pointing outside of the file (int32(1852796448)).

Thank you for your contribution. For easy vendoring I have released v1.1.0