devongovett / exif-reader

A small EXIF image metadata reader
MIT License
145 stars 22 forks source link

Little endian EXIF within a HEIF image #32

Closed uasan closed 10 months ago

uasan commented 10 months ago

Hey. Gives an error when trying to read exif data from .avif format

Error: Invalid EXIF data: buffer should start with "Exif", "MM" or "II".

Does this library not support avif parsing?

devongovett commented 10 months ago

This library only parses exif, it does not handle parsing the format that contains it (eg jpeg, avif, etc). You'd need to use a different library to extract the exif buffer from the image format you're working with and then pass that buffer to this library to decode it.

uasan commented 10 months ago

Hey, that's what I do

    const meta = await sharp(await file.arrayBuffer()).metadata();
    if (meta.exif) console.log(exif(meta.exif));

Result in meta

{
  format: 'heif',
  size: 21018,
  width: 630,
  height: 420,
  space: 'srgb',
  channels: 3,
  depth: 'uchar',
  isProgressive: false,
  pages: 1,
  pagePrimary: 0,
  compression: 'hevc',
  hasProfile: false,
  hasAlpha: false,
  exif: <Buffer 49 49 2a 00 08 00 00 00 01 00 98 82 02 00 17 00 00 00 1a 00 00 00 00 00 00 00 77 77 77 2e 6c 69 62 72 65 2d 73 6f 66 74 77 61 72 65 2e 6e 65 74 00 00>
}

Error in exif-reader

Error: Invalid EXIF data: buffer should start with "Exif", "MM" or "II".
lovell commented 10 months ago

The start of this EXIF data 49 49 2a 00 ... looks like valid big endian encoding, however the current code incorrectly assumes the 3rd byte of big endian EXIF will be zero.

https://github.com/devongovett/exif-reader/blob/27420cb3253d99c9d5d24e1cfcc0d5994ca8716c/index.js#L5

So I think this might be a bug parsing big endian EXIF.

@uasan Do you know the source of this image? It looks like a HEIC image rather than AVIF.

uasan commented 10 months ago

@lovell , yes, this is a HEIC, but it looks like an AVIF, here is the link to the photo https://cdn.glitch.global/75170424-3d76-41d7-ae77-72d0efb0401b/AVIF%20Test%20picture%20(JPEG%20converted%20to%20AVIF%20with%20Convertio).avif?v=1658240752363

lovell commented 9 months ago

Apologies, I got this slightly the wrong way round. 49 49 ... is hex for II .. and therefore this image is Intel order / little endian. However the same thing applies, I think there's still a bug here, namely the 3rd byte will not be zero.