Twinside / Juicy.Pixels

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

Fix the handling of ExifUndefined data of 4 bytes or fewer. #188

Closed ppelleti closed 3 years ago

ppelleti commented 3 years ago

For example, this was causing the EXIF version (tag 0x9000) to come out as "0000" instead of "0320".

Here is a test program and image which demonstrates the bug: exif-test-version.zip

The compiler was interpreting:

              [fromIntegral $ ofs .&. 0xFF000000 `unsafeShiftR` (3 * 8)
              ,fromIntegral $ ofs .&. 0x00FF0000 `unsafeShiftR` (2 * 8)
              ,fromIntegral $ ofs .&. 0x0000FF00 `unsafeShiftR` (1 * 8)
              ,fromIntegral $ ofs .&. 0x000000FF
              ]

as:

              [fromIntegral $ ofs .&. (0xFF000000 `unsafeShiftR` (3 * 8))
              ,fromIntegral $ ofs .&. (0x00FF0000 `unsafeShiftR` (2 * 8))
              ,fromIntegral $ ofs .&. (0x0000FF00 `unsafeShiftR` (1 * 8))
              ,fromIntegral $ ofs .&. 0x000000FF
              ]

which is the same as:

              [fromIntegral $ ofs .&. 0x000000FF
              ,fromIntegral $ ofs .&. 0x000000FF
              ,fromIntegral $ ofs .&. 0x000000FF
              ,fromIntegral $ ofs .&. 0x000000FF
              ]

i. e. repeating the last byte four times.