kamadak / exif-rs

Exif parsing library written in pure Rust
BSD 2-Clause "Simplified" License
190 stars 42 forks source link

InvalidFormat("Unexpected next IFD") #31

Open evanw opened 1 year ago

evanw commented 1 year ago

I have a JPEG image generated by a FLIR camera:

I traced through this library and it looks like the child IFD for Tag::GPSInfoIFDPointer has a next_ifd_offset of -1 (i.e. 0xFF_FF_FF_FF) instead of 0, which causes this library to fail with InvalidFormat("Unexpected next IFD").

The file is able to be parsed using exiftool. I traced through its Perl code and it seems like exiftool only parses the next IFD if the tag is known to have a next IFD. So maybe it's safe to just ignore the next IFD offset for child IFDs instead of validating the offset? That would allow this library to read EXIF metadata from files like this one. What do you think?

kamadak commented 1 year ago

Your analysis is correct. I am adding a more general "recovery from error" mode to the version 0.6 of this library.

gzsombor commented 1 year ago

I've noticed, that someone already hacked a solution for this problem : https://github.com/vabock/exif-rs/commit/76ee369bf4766af200679f17e216dfda51a262e0 This solved my similar problem, maybe you can merge this fix, and release the library. What do you think?