Skip to content

Crash when setting width/height on canvas: core dumped #2520

@948764321

Description

@948764321

Title: Intermittent bug in canvas. width assignment after specific operations (v3.1.1)

Description:
After updating to node-canvas v3.1.1, my application started failing intermittently when assigning values to canvas.width.

Key observations:

The failure occurs only in my existing application code

Cannot reproduce with a minimal standalone demo containing only canvas. width assignments

The critical difference:

In my application, additional operations precede the canvas. width assignment

These pre-assignment operations appear to trigger the failure

Evidence:
The same error occurs in

import { createCanvas } from 'canvas';
import fs from 'node:fs';

const canvas = createCanvas(1, 1, 'pdf');
const context = canvas.getContext('2d');

context.canvas.width = 595.3; // <------- crashes
context.canvas.width = 595.3; // <------- crashes
context.canvas.width = 595.3; // <------- crashes
context.canvas.width = 595.3; // <------- crashes
context.canvas.height = 595.3; // <------- crashes

context.fillStyle = 'green';
context.fillRect(10, 10, 150, 100);

const pngStream = canvas.createPDFStream();
const out = fs.createWriteStream('./output.pdf');
pngStream.pipe(out);

out.once('finish', () => {
  console.log('✓ saved as output.pdf');
});

suggesting this is a regression in v3.1.1 related to canvas state management when modifying properties after certain operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions