pwlmaciejewski / imghash

Perceptual image hashing for Node.js
MIT License
167 stars 19 forks source link

Error: Not implemented On some images #21

Closed MouseAndKeyboard closed 4 years ago

MouseAndKeyboard commented 4 years ago

I'm writing a project which downloads images and then hashes them, storing the result.

Most images work fine, for example: 03dcf908de492beed0776fd3817e5b0d547bd87c Link Works as expected.

However: 6d2ef973522fd71f0e0ea0326e1d6fbbfc6c567c Link

Fails to hash and throws the following error:

Error: Not implemented
    at longjmp (/home/acc/Website/node_modules/@cwasm/jpeg-turbo/index.js:12:22)
    at wasm-function[204]:0x1e969
    at wasm-function[60]:0xa3f5
    at wasm-function[59]:0x92c6
    at wasm-function[209]:0x1f064
    at Object.exports.decode (/home/acc/Website/node_modules/@cwasm/jpeg-turbo/index.js:68:39)
    at decodeImage (/home/acc/Website/node_modules/@canvas/image/index.js:20:17)
    at imageFromBuffer /home/acc/Website/node_modules/@canvas/image/index.js:185:29)
    at /home/acc/Website/node_modules/imghash/index.js:17:22
    at new Promise (<anonymous>)

I suspect the image is somehow corrupted but I'm not good enough with image encodings to understand how.

After running them through an online file type checker I get the following results: (For the correctly-working image):

File Size | 1202 bytes
-- | --
File Type | JPEG
File Type Extension | jpg
MIME Type | image/jpeg
Image Width | 32
Image Height | 32
Encoding Process | Baseline DCT, Huffman coding
Bits Per Sample | 8
Color Components | 3
Y Cb Cr Sub Sampling | YCbCr4:2:0 (2 2)
JFIF Version | 1.01
Resolution Unit | None
X Resolution | 1
Y Resolution | 1
Image Size | 32x32
Megapixels | 0.001

For the broken/corrupt image

File Size | 2.6 kB
-- | --
File Type | JPEG
File Type Extension | jpg
MIME Type | image/jpeg
Image Width | 32
Image Height | 32
Encoding Process | Baseline DCT, Huffman coding
Bits Per Sample | 8
Color Components | 4
JFIF Version | 1.01
Resolution Unit | inches
X Resolution | 120
Y Resolution | 120
DCT Encode Version | 100
APP14 Flags 0 | (none)
APP14 Flags 1 | (none)
Color Transform | Unknown (RGB or CMYK)
Image Size | 32x32
Megapixels | 0.001

This corroborates my belief that the images are somehow different. These images are submitted by users so it could be possible that the image was maliciously crafted in order to be buggy/corrupted.

pwlmaciejewski commented 4 years ago

Confirmed, it does fail for me as well. @LinusU Is this something that can be fixed in cwasm-jpeg-turbo?

LinusU commented 4 years ago

First of all, sorry for the very long delay in getting to this.

This is super interesting! I thought that long-jump was just used for error handling in jpeg-turbo, but maybe I was wrong 🤔

I've filed an issue upstream here: https://github.com/LinusU/cwasm-jpeg-turbo/issues/2

bbhopesh commented 4 years ago

Anyone found a workaround for this?

bbhopesh commented 4 years ago

Hey @LinusU @pwlmaciejewski can you please look at pull request that adds a workaround for this bug? I need this workaround to get merged so we can continue using imghash.

bbhopesh commented 4 years ago

Hey @pwlmaciejewski, I see that you liked my previous comment. Can you please also merge the PR and generate and publish new package? I can't merge it because I don't have permissions.

pwlmaciejewski commented 4 years ago

Hi @bbhopesh, thank you for your contribution! I'm going to check it as soon as I can, I'll keep you posted.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

pwlmaciejewski commented 4 years ago

@bbhopesh bump

pwlmaciejewski commented 4 years ago

Fixed and released in v0.0.8. Thank you @bbhopesh for taking care of it!

bbhopesh commented 4 years ago

It's my pleasure. @pwlmaciejewski