createImageData() with negative width and height aborts the process
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
Direzione di ricerca
Inizia leggendo Context2d::CreateImageData, menzionato nell’issue, e segui come converte larghezza e altezza prima di allocare il buffer. Confronta il comportamento con la specifica Canvas citata e riproduci i due casi con dimensioni negative dello script fornito. Il lavoro è concluso quando entrambi restituiscono dimensioni positive senza generare eccezioni né interrompersi; aggiungi o esegui test mirati per questi casi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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/
- Lingua principale
- JavaScript
- Stelle
- 10.7k
- Fork
- 1.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Automattic/node-canvas
-
Feature Text & Fonts
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
Automattic/node-canvas#2364 · 3 commenti · 2 reazioni ·
-
Feature
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
Automattic/node-canvas#2621 ·
-
actualBoundingBoxLeft has the sign inverted relative to canvas's own rasteriser (3.2.0, 3.2.3)Forse già presa @florianaltendorfer l’ha presa 13 giorni fa. ApertaBug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
Automattic/node-canvas#2620 · 1 commento ·
-
Bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Automattic/node-canvas#2619 · 1 commento ·
-
The PDF file created by createPDFStream becomes larger in size, and createWriteStream is very slowApertaBug performance
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Automattic/node-canvas#2615 · 2 commenti ·
Tutte le issue di Automattic/node-canvas
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
capricorn86/happy-dom#2594 ·
I maintainer di solito rispondono entro 1 giorno
-
Decoding tag 1 (epoch date) with an 8-byte integer throws "Cannot mix BigInt and other types"Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
microsoft/monaco-editor#5575 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
Shrinking an array with `length =` and growing it back loses the patches for the truncated indicesForse già presa @RClaudiuM l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 4 giorni