Twinside / Juicy.Pixels

Haskell library to load & save pictures
BSD 3-Clause "New" or "Revised" License
238 stars 57 forks source link

Fix endianness bug in short ExifString and ExifUndefined. #191

Closed ppelleti closed 3 years ago

ppelleti commented 3 years ago

When ExifString and ExifUndefined are four bytes or fewer, they are packed into the "offset" field. Since string and undefined are byte-oriented, they should appear in sequential order in the file and do not need to be byte-swapped. However, the ifdOffset field has already been byte-swapped. Therefore, for little-endian files, we need to swap ifdOffset back to undo the byte swapping.

A symptom was that ExifVersion was showing up as "0320", although there is no version 3.2 of EXIF, and exiftool shows the version correctly as "0230":

$ exif-test
Just (ExifUndefined "0320")
$ exiftool -ExifVersion test-image.jpg
Exif Version                    : 0230

After this fix, JuicyPixels correctly reports version "0230":

$ exif-test
Just (ExifUndefined "0230")

Test program and image which demonstrate the problem: exif-test-version.zip