Automattic / Automattic/node-canvas

Loading a JPEG with precision set to 12 crashes all processes

Open
#1,160 8 comments 0 reactions 0 assignees View on GitHub
Bug Images & Formats: JPEG
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

When attempting to set the `src` property of a `Canvas.Image` object with a `Buffer`, all processes (`node-canvas`, our user app, etc) crash if the buffer contains a JPEG image with precision set to 12 bits.

Interestingly, wrapping the `src` set in a `try/catch` does not catch the error. The only way to catch it is visually by running the process and watching the command line, which will produce the following:
```
< Unsupported JPEG data precision 12
```

I have also tried to set the `img.onerror` handler to get more context, however it seems this is never called before the process(es) crash.

## Steps to Reproduce

```js
const fileName = 'myImage.jpg';

require('fs').readFile(require('path').resolve(__dirname, fileName), (err, data) => {
if (err) {
console.log(err);
process.exit(1);
}

const Image = require('canvas').Image;
let img = new Image();
img.src = data; // <-- this is the call that crashes everything

console.log('success');
});
```

## Your Environment
* Version of node-canvas: 1.6.9
* Environment: node 8.9.4 on Mac OSX 10.12.6

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.