-
Notifications
You must be signed in to change notification settings - Fork 126
Description
Hello,
I'm using jimp, which use your library. I have a problem with some images, which, when I want to preview them with jimp, throw a JS error:
TypeError: Cannot read property '0' of undefined
at decodeBlock (XXXXXXXXXXX\node_modules\jpeg-js\lib\decoder.js:264:51)
at decodeScan (XXXXXXXXXXX\node_modules\jpeg-js\lib\decoder.js:298:11)
at constructor.parse (XXXXXXXXXXX\node_modules\jpeg-js\lib\decoder.js:744:29)
at Object.decode [as image/jpeg] (XXXXXXXXXXX\node_modules\jpeg-js\lib\decoder.js:1004:11)
at Jimp.parseBitmap (XXXXXXXXXXX\node_modules\@jimp\core\dist\utils\image-bitmap.js:115:53)
at Jimp.parseBitmap (XXXXXXXXXXX\node_modules\@jimp\core\dist\index.js:521:32)
at new Jimp (XXXXXXXXXXX\node_modules\@jimp\core\dist\index.js:474:13)
at _construct (XXXXXXXXXXX\node_modules\@babel\runtime\helpers\construct.js:30:21)
at XXXXXXXXXXX\node_modules\@jimp\core\dist\index.js:1016:32
at new Promise (<anonymous>)
at Function.Jimp.read (XXXXXXXXXXX\node_modules\@jimp\core\dist\index.js:1015:10)
...
I'm pretty sure this is due to the fact that the image must have an invalid format, but it is nevertheless read by all the readers I've tested (Chrome, Paint, Photoshop, Windows Photos, ...).
And after trying to update your lib, so as not to call the function if the value is undefined, it works perfectly (my preview is generated by jimp):
function decodeBlock(component, decode, mcu) {
var blockRow = (mcu / component.blocksPerLine) | 0;
var blockCol = mcu % component.blocksPerLine;
if (component.blocks[blockRow] !== undefined) {
decode(component, component.blocks[blockRow][blockCol]);
}
}I'm doing this issue rather than a PR because I don't know anything about the JPEG format, and I don't know if it can have unintended consequences. What do you think about that? Is it possible to fix it? If my if is enough, I can of course do the PR to help you.
I would have appreciated being able to share these images to show you an example of the issue, but these images are private. And if I edit them to remove the private parts, the problem disappears...