jimp-dev / jimp

An image processing library written entirely in JavaScript for Node, with zero external or native dependencies.
http://jimp-dev.github.io/jimp/
MIT License
14.05k stars 760 forks source link

Uncaught exception with malformed PNG #1261

Open Lambdac0re opened 1 year ago

Lambdac0re commented 1 year ago

Expected Behavior

Either not crashing or properly handling of the error (useful error message for example).

Current Behavior

Error: End-Of-Stream
    at BufferTokenizer.peekBuffer (C:\js\yeet-ocr\node_modules\strtok3\lib\BufferTokenizer.js:44:19)
    at BufferTokenizer.readBuffer (C:\js\yeet-ocr\node_modules\strtok3\lib\BufferTokenizer.js:30:38)
    at BufferTokenizer.readToken (C:\js\yeet-ocr\node_modules\strtok3\lib\AbstractTokenizer.js:25:32)
    at readChunkHeader (C:\js\yeet-ocr\node_modules\file-type\core.js:978:29)
    at _fromTokenizer (C:\js\yeet-ocr\node_modules\file-type\core.js:984:24)
    at async getMIMEFromBuffer (C:\js\yeet-ocr\node_modules\@jimp\core\dist\utils\image-bitmap.js:19:30)
    at async Jimp.parseBitmap (C:\js\yeet-ocr\node_modules\@jimp\core\dist\utils\image-bitmap.js:149:16)

Failure Information (for bugs)

Steps to Reproduce

Use attached file:

Jimp
.read(buffer)
.then(jimpObj => jimpObj.getBufferAsync(Jimp.MIME_PNG))

Context

Failure Logs

broken-png

Lambdac0re commented 1 year ago

The same file gives you this useful error message with sharp: "Input buffer has corrupt header: pngload_buffer: end of stream"

Lambdac0re commented 9 months ago

Here is another example:

https://i.imgur.com/dYKD1.png