Automattic / Automattic/node-canvas

Segmentation Fault in PutImageData

Open
#1,972 5 comments 2 reactions 0 assignees View on GitHub
Bug Help wanted
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

## Issue or Feature
- [x] If this is an issue with installation, I have read the [troubleshooting guide](https://github.com/Automattic/node-canvas/issues/1511).

PID 14986 received SIGSEGV for address: 0x9bf00803
/home/pi/Discord-Bot/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x25f4)[0xf72df5f4]
/lib/arm-linux-gnueabihf/libc.so.6(__default_rt_sa_restorer+0x0)[0xf7b28db0]
/home/pi/Discord-Bot/node_modules/canvas/build/Release/canvas.node(_ZN9Context2d12PutImageDataERKN3Nan20FunctionCallbackInfoIN2v85ValueEEE+0x684)[0xf4c331b4]
/home/pi/Discord-Bot/node_modules/canvas/build/Release/canvas.node(+0x23db4)[0xf4c29db4]

## Steps to Reproduce

```js
const canvas = new Canvas.createCanvas();

const ctx = canvas.getContext('2d');

ctx.canvas.width = 1024;
ctx.canvas.height = 576;

const base = await Canvas.loadImage(avatarURL);

var hRatio = canvas.width / base.width;
var vRatio = canvas.height / base.height;
var ratio = Math.min(hRatio, vRatio);
var centerShift_x = (canvas.width - base.width * ratio) / 2;
var centerShift_y = (canvas.height - base.height * ratio) / 2;

ctx.drawImage(base, 0, 0, base.width, base.height, // source rectangle
centerShift_x, centerShift_y, base.width * ratio - 10, base.height * ratio - 10); // destination rectangle

var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
var pix = imgData.data;
//convert the image into a silhouette
for (var i = 0, n = pix.length; i < n; i += 4) {
//set red to 0
pix[i] = 0;
//set green to 0
pix[i + 1] = 0;
//set blue to 0
pix[i + 2] = 0;
//retain the alpha value
pix[i + 3] = pix[i + 3];
}
await ctx.putImageData(imgData, 0, 0);

canvas.toBuffer()
```

## Your Environment
* Version of node-canvas (output of `npm list canvas` or `yarn list canvas`): 2.9.0
* Environment (e.g. node 4.2.0 on Mac OS X 10.8): Raspberry Pi OS , Debian bullseye

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.