Automattic / Automattic/node-canvas

Segfault on Windows while drawing single-char strings

Open
#1,162 2 comments 1 reaction 0 assignees View on GitHub
Bug Text & Fonts
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

### Issue or Feature
Sometimes drawing strings of length 1 causes segfault on Windows.

### Steps to Reproduce
It's crashing on `measureText` call, but I can't investigate it at the moment.
```js
'use strict';

var s = 100;
var sh = s / 2;

var g = new (require('canvas').Canvas)(s, s).getContext('2d');
g.textBaseline = 'middle';
g.textAlign = 'center';
g.font = '32px sans-serif';
g.fillStyle = 'black';

var j = 0;
var w = 0;

for(var i = 0; i < 2 ** 16; i++){
var c = String.fromCharCode(i);

g.clearRect(0, 0, s, s);
g.fillText(c, sh, sh);

if(!g.getImageData(0, 0, s, s).data.some(a => a))
continue;

var w1 = g.measureText(c).width; // <------ Seems to crash here
if(w1 <= w)
continue;

w = w1;
j = i;
}

console.log(`\\u${j.toString(16).padStart(4, '0')}`);
```

### Your Environment
* Version of node-canvas: master
* Environment: node v10.1.0 windows 8.1

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.