createImageData() with negative width and height aborts the process
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 76/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, node.js
调研方向
先阅读 issue 中提到的 Context2d::CreateImageData,并追踪它在分配缓冲区之前如何转换宽度和高度。将其行为与引用的 Canvas 规范进行比较,并复现所提供脚本中的两个负尺寸情况。完成标准是这两种情况都返回正尺寸,且不会抛出异常或中止;为这些情况添加或运行有针对性的测试。
由索引模型根据 Issue 内容生成。
描述
Version of node-canvas
v3.2.3, v4.0.0-rc3 (master 6cc138b)
Version of node
v26.13.0
What operating system does the problem occur on?
Linux
Steps to reproduce
ctx.createImageData(sw, sh) should use the absolute values of sw and sh. In node-canvas a negative size is read as a huge unsigned number: one negative argument throws, and two negative arguments abort Node with a fatal out-of-memory error that cannot be caught.
const { createCanvas } = require('canvas');
const ctx = createCanvas(10, 10).getContext('2d');
try { const d = ctx.createImageData(-3, 2); console.log(d.width, d.height); } catch (e) { console.log('threw:', e.message); }
const d = ctx.createImageData(-3, -2);
console.log(d.width, d.height);
Run node repro.js; echo $?:
Actual:
threw: buffer exceeds 2147483647 bytes
FATAL ERROR: v8::ArrayBuffer::New Allocation failed - process out of memory
...
134
Expected (matches Chrome 153):
3 2
3 2
Additional information/comments
Per https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createimagedata, createImageData(sw, sh) must initialize the ImageData object with the absolute magnitude of sw and sh. In Context2d::CreateImageData, the arguments are converted with Uint32Value(), turning -3 into 4294967293; with two negative values Bpp * width * height overflows int64_t, bypasses the nBytes > INT32_MAX check, and passes a negative nBytes to Napi::ArrayBuffer::New.
Credit: https://ucsbplse.github.io/
- 主要语言
- JavaScript
- 星标
- 10.7k
- 派生
- 1.2k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Automattic/node-canvas 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 79/100
Automattic/node-canvas#2634 ·
-
Feature Text & Fonts
难度 1/5 1 小时以内 新手友好度 78/100
Automattic/node-canvas#2364 · 3 条评论 · 2 个 reaction ·
-
Feature
难度 4/5 3-5 天 新手友好度 48/100
Automattic/node-canvas#2621 ·
-
actualBoundingBoxLeft has the sign inverted relative to canvas's own rasteriser (3.2.0, 3.2.3)可能已有人在做 @florianaltendorfer 于 15 天前认领。 未关闭Bug
难度 3/5 1-2 天 新手友好度 68/100
Automattic/node-canvas#2620 · 1 条评论 ·
-
Bug
难度 4/5 3-5 天 新手友好度 35/100
Automattic/node-canvas#2619 · 1 条评论 ·
查看 Automattic/node-canvas 的全部 Issue
相似的 Issue
-
status: ready
难度 2/5 1-3 小时 新手友好度 68/100
melodic-software/claude-code-plugins#14389 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
needs triage
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 83/100
Fei2411/DeepSeek-Bot#1194 ·