Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.2k stars 1.17k forks source link

Node crashes when passing canvas with width or height 0 to createPNGStream() #2443

Open six5536 opened 1 month ago

six5536 commented 1 month ago

Node: v20, v22.8.0 node-canvas: v2.11.2

Node crashes when passing canvas with width or height 0 to createPNGStream(). Ok, this is not a valid thing to do, but it should not crash node.

const canvas = new Canvas(12, 0);
const out = fs.createWriteStream('image.png');
const stream = canvas.createPNGStream();
stream.pipe(out);
out
        .on('close', () => {
          console.log('close, happens');
        })
        .on('finish', () => {
          console.log('finish, never happens, node crashes');
        })
        .on('error', () => {
          console.log('error, never happens, node crashes');
        })