mooyoul / get-orientation

Get orientation from EXIF of image file. Supports both Browser and Node.js
https://mooyoul.github.io/get-orientation/
MIT License
117 stars 3 forks source link

Getting AssertionError when trying to get orientation of certain image #94

Open ilyai opened 1 year ago

ilyai commented 1 year ago

It works fine for most of the images, but I've found an image which get-orientation fails to process. The error message is the following:

node:assert:399
    throw err;
    ^

AssertionError [ERR_ASSERTION]: can only skip > 0 bytes, got "-4"
    at EXIFOrientationParser._skipBytes (/Users/iig/IdeaProjects/fugo-media-processor/node_modules/stream-parser/index.js:117:3)
    at EXIFOrientationParser.<anonymous> (/Users/iig/IdeaProjects/fugo-media-processor/node_modules/get-orientation/index.js:48:26)
    at process (/Users/iig/IdeaProjects/fugo-media-processor/node_modules/stream-parser/index.js:270:20)
    at /Users/iig/IdeaProjects/fugo-media-processor/node_modules/stream-parser/index.js:204:14
    at /Users/iig/IdeaProjects/fugo-media-processor/node_modules/stream-parser/index.js:294:16
    at EXIFOrientationParser.write [as _write] (/Users/iig/IdeaProjects/fugo-media-processor/node_modules/stream-parser/index.js:157:3)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at EXIFOrientationParser.Writable.write (node:internal/streams/writable:334:10)
    at ReadStream.ondata (node:internal/streams/readable:754:22) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

Here is the image which makes get-orientation to fail:

lookupstrata_logo

I'm using the latest version of the package: 1.1.2

mooyoul commented 1 year ago

Hello there! Thank you for reporting.

Just checked the image and noticed that image contains "empty" non-EXIF APP1 marker which expressed to 2 bytes segment length. Currently parser assumes APP1 segment length to be greater or equal than 8 bytes for non-EXIF APP1 segment to skip unnecessary bytes, but that 2 bytes segment length made parser to skip negative bytes (-6 bytes). So this resulted to that error.

I thought that I've tested get-orientation with many "corrupted" JPEG images, but wow. your case is not covered by that test images. I can fix this issue and I will include this image to "corrupted" image set for testing. but hey, Can I use this image for testing? I have concerns about image licensing.

Unfortunately, I cannot guarantee an ETA at this moment but expected to be resolved in next 2 weeks - I've been super busy recent days and I don't have enough spare time to fix this issue 😭

Anyway thanks again for reporting this and this was super helpful for me. Stay tuned!