pixels: Add limitation to max image total bytes length (#37172)

Limit the maximum image allocation size to 2GB to minimize the
possibility of out of memory errors on some `ImageBitmap`, `ImageData`,
`Canvas`, and `OffscreenCanvas` operations such as construction,
`toBlob`, and `toDataURL`. Other browsers have similar limits:
 - Chromium: 2^32-1 (~4GB)
- Firefox: 2^31-1 (~2GB)

Testing: Improvements to the following tests:
-
`html/canvas/element/pixel-manipulation/2d.imageData.object.ctor.basics.html`
assert_throws_dom("INDEX_SIZE_ERR", function() { new ImageData(1 << 31,
1 << 31); });
-
`html/canvas/element/manual/imagebitmap/createImageBitmap-invalid-args.html`
   makeOversizedCanvas + makeOversizedOffscreenCanvas

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This commit is contained in:
Andrei Volykhin 2025-05-29 13:43:27 +03:00 committed by GitHub
parent 3bb7c71eb6
commit 801ac9e22a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 93 additions and 150 deletions

View file

@ -1,5 +1,5 @@
[createImageBitmap-invalid-args.html]
expected: CRASH
expected: ERROR
[createImageBitmap with a vector HTMLImageElement source and sw set to 0]
expected: FAIL
@ -10,16 +10,13 @@
expected: FAIL
[createImageBitmap with a broken image source.]
expected: NOTRUN
[createImageBitmap with WebGLRenderingContext image source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a Blob source and sw set to 0]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an available but zero height image source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an HTMLVideoElement source and sh set to 0]
expected: FAIL
@ -28,25 +25,19 @@
expected: FAIL
[createImageBitmap with a Blob source and sh set to 0]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an HTMLVideoElement from a data URL source and sw set to 0]
expected: FAIL
[createImageBitmap with null image source.]
expected: NOTRUN
[createImageBitmap with an ImageData source and sh set to 0]
expected: NOTRUN
[createImageBitmap with undefined image source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an undecodable blob source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an available but undecodable image source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region]
expected: FAIL
@ -55,13 +46,13 @@
expected: FAIL
[createImageBitmap with a vector SVGImageElement source and oversized (unallocatable) crop region]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an HTMLCanvasElement source and oversized (unallocatable) crop region]
expected: FAIL
[createImageBitmap with an ImageBitmap source and oversized (unallocatable) crop region]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an HTMLVideoElement source and oversized (unallocatable) crop region]
expected: FAIL
@ -70,187 +61,112 @@
expected: FAIL
[createImageBitmap with an ImageData source and sw set to 0]
expected: NOTRUN
[createImageBitmap with an invalid OffscreenCanvas source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an OffscreenCanvas source and sh set to 0]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an OffscreenCanvas source and sw set to 0]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an HTMLVideoElement from a data URL source and sh set to 0]
expected: FAIL
[createImageBitmap with an ImageData source and oversized (unallocatable) crop region]
expected: NOTRUN
[createImageBitmap with ArrayBuffer image source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a bitmap SVGImageElement source and oversized (unallocatable) crop region]
expected: NOTRUN
[createImageBitmap with an oversized canvas source.]
expected: NOTRUN
[createImageBitmap with Uint8Array image source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a vector SVGImageElement source and sh set to 0]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an HTMLCanvasElement source and sh set to 0]
expected: FAIL
[createImageBitmap with a closed ImageBitmap.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a bitmap HTMLImageElement source and oversized (unallocatable) crop region]
expected: FAIL
[createImageBitmap with empty image source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with empty video source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a bitmap SVGImageElement source and sw set to 0]
expected: TIMEOUT
expected: FAIL
[createImageBitmap with an ImageBitmap source and sh set to 0]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an available but zero width image source.]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a vector SVGImageElement source and sw set to 0]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a Blob source and oversized (unallocatable) crop region]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a bitmap SVGImageElement source and sh set to 0]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an ImageBitmap source and sw set to 0]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a bitmap HTMLImageElement source and sw set to 0]
expected: FAIL
[createImageBitmap with an OffscreenCanvas source and oversized (unallocatable) crop region]
expected: NOTRUN
[createImageBitmap with CanvasRenderingContext2D image source.]
expected: NOTRUN
[createImageBitmap with a vector HTMLImageElement source and a value of 0 int resizeWidth]
expected: FAIL
[createImageBitmap with a vector HTMLImageElement source and a value between 0 and 1 in resizeWidth]
expected: FAIL
[createImageBitmap with an OffscreenCanvas source and a value of 0 in resizeHeight]
expected: NOTRUN
[createImageBitmap with a bitmap SVGImageElement source and a value of 0 in resizeHeight]
expected: NOTRUN
[createImageBitmap with an ImageData source and a value between 0 and 1 in resizeWidth]
expected: NOTRUN
[createImageBitmap with a vector SVGImageElement source and a value of 0 int resizeWidth]
expected: NOTRUN
[createImageBitmap with an ImageBitmap source and a value between 0 and 1 in resizeWidth]
expected: NOTRUN
[createImageBitmap with an ImageBitmap source and a value of 0 int resizeWidth]
expected: NOTRUN
[createImageBitmap with an ImageData source and a value of 0 in resizeHeight]
expected: NOTRUN
[createImageBitmap with an HTMLVideoElement source and a value between 0 and 1 in resizeWidth]
expected: FAIL
[createImageBitmap with an OffscreenCanvas source and a value between 0 and 1 in resizeWidth]
expected: NOTRUN
[createImageBitmap with a vector SVGImageElement source and a value of 0 int resizeWidth]
expected: FAIL
[createImageBitmap with an ImageBitmap source and a value between 0 and 1 in resizeWidth]
expected: FAIL
[createImageBitmap with an ImageBitmap source and a value of 0 int resizeWidth]
expected: FAIL
[createImageBitmap with a vector SVGImageElement source and a value between 0 and 1 in resizeHeight]
expected: NOTRUN
[createImageBitmap with a Blob source and a value of 0 int resizeWidth]
expected: NOTRUN
[createImageBitmap with an HTMLVideoElement source and a value of 0 in resizeHeight]
expected: FAIL
[createImageBitmap with an HTMLVideoElement from a data URL source and a value between 0 and 1 in resizeWidth]
expected: FAIL
[createImageBitmap with a vector SVGImageElement source and a value of 0 in resizeHeight]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a bitmap SVGImageElement source and a value between 0 and 1 in resizeHeight]
expected: NOTRUN
[createImageBitmap with a Blob source and a value between 0 and 1 in resizeHeight]
expected: NOTRUN
[createImageBitmap with a Blob source and a value between 0 and 1 in resizeWidth]
expected: NOTRUN
[createImageBitmap with a vector HTMLImageElement source and a value between 0 and 1 in resizeHeight]
expected: FAIL
[createImageBitmap with an HTMLVideoElement from a data URL source and a value of 0 in resizeHeight]
expected: FAIL
[createImageBitmap with an ImageBitmap source and a value of 0 in resizeHeight]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an ImageBitmap source and a value between 0 and 1 in resizeHeight]
expected: NOTRUN
expected: FAIL
[createImageBitmap with a bitmap SVGImageElement source and a value between 0 and 1 in resizeWidth]
expected: NOTRUN
[createImageBitmap with an HTMLVideoElement source and a value between 0 and 1 in resizeHeight]
expected: FAIL
[createImageBitmap with an HTMLVideoElement source and a value of 0 int resizeWidth]
expected: FAIL
[createImageBitmap with an OffscreenCanvas source and a value of 0 int resizeWidth]
expected: NOTRUN
[createImageBitmap with a vector HTMLImageElement source and a value of 0 in resizeHeight]
expected: FAIL
[createImageBitmap with an OffscreenCanvas source and a value between 0 and 1 in resizeHeight]
expected: NOTRUN
[createImageBitmap with a bitmap SVGImageElement source and a value of 0 int resizeWidth]
expected: NOTRUN
expected: FAIL
[createImageBitmap with an HTMLVideoElement from a data URL source and a value of 0 int resizeWidth]
expected: FAIL
[createImageBitmap with an ImageData source and a value between 0 and 1 in resizeHeight]
expected: NOTRUN
[createImageBitmap with an HTMLVideoElement from a data URL source and a value between 0 and 1 in resizeHeight]
expected: FAIL
[createImageBitmap with an ImageData source and a value of 0 int resizeWidth]
expected: NOTRUN
[createImageBitmap with a vector SVGImageElement source and a value between 0 and 1 in resizeWidth]
expected: NOTRUN
[createImageBitmap with a Blob source and a value of 0 in resizeHeight]
expected: NOTRUN
expected: FAIL