diff options
author | Hajime-san <41257923+Hajime-san@users.noreply.github.com> | 2024-05-06 22:26:25 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-06 06:26:25 -0700 |
commit | a635abbf2136f5512543551af6a6c37b5e9aa4ba (patch) | |
tree | 8b1055d38f550e67b42c2290e7a084d6bf647703 /ext/webgpu | |
parent | 4ab68df33efdb49b1520767d3f45e6b4294c4c11 (diff) |
fix(ext/webgpu): correctly validate GPUExtent3D, GPUOrigin3D, GPUOrigin2D & GPUColor (#23413)
Diffstat (limited to 'ext/webgpu')
-rw-r--r-- | ext/webgpu/01_webgpu.js | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js index 5ca8c0fdb..be0b87cdf 100644 --- a/ext/webgpu/01_webgpu.js +++ b/ext/webgpu/01_webgpu.js @@ -1136,10 +1136,11 @@ class GPUDevice extends EventTarget { "Argument 1", ); const device = assertDevice(this, prefix, "this"); + // assign normalized size to descriptor due to createGPUTexture needs it + descriptor.size = normalizeGPUExtent3D(descriptor.size); const { rid, err } = op_webgpu_create_texture({ deviceRid: device.rid, ...descriptor, - size: normalizeGPUExtent3D(descriptor.size), }); device.pushError(err); @@ -5501,6 +5502,16 @@ webidl.converters["GPUExtent3D"] = (V, opts) => { if (typeof V === "object") { const method = V[SymbolIterator]; if (method !== undefined) { + // validate length of GPUExtent3D + const min = 1; + const max = 3; + if (V.length < min || V.length > max) { + throw webidl.makeException( + TypeError, + `A sequence of number used as a GPUExtent3D must have between ${min} and ${max} elements.`, + opts, + ); + } return webidl.converters["sequence<GPUIntegerCoordinate>"](V, opts); } return webidl.converters["GPUExtent3DDict"](V, opts); @@ -6836,6 +6847,15 @@ webidl.converters["GPUOrigin3D"] = (V, opts) => { if (typeof V === "object") { const method = V[SymbolIterator]; if (method !== undefined) { + // validate length of GPUOrigin3D + const length = 3; + if (V.length > length) { + throw webidl.makeException( + TypeError, + `A sequence of number used as a GPUOrigin3D must have at most ${length} elements.`, + opts, + ); + } return webidl.converters["sequence<GPUIntegerCoordinate>"](V, opts); } return webidl.converters["GPUOrigin3DDict"](V, opts); @@ -6904,6 +6924,15 @@ webidl.converters["GPUOrigin2D"] = (V, opts) => { if (typeof V === "object") { const method = V[SymbolIterator]; if (method !== undefined) { + // validate length of GPUOrigin2D + const length = 2; + if (V.length > length) { + throw webidl.makeException( + TypeError, + `A sequence of number used as a GPUOrigin2D must have at most ${length} elements.`, + opts, + ); + } return webidl.converters["sequence<GPUIntegerCoordinate>"](V, opts); } return webidl.converters["GPUOrigin2DDict"](V, opts); @@ -6989,6 +7018,15 @@ webidl.converters["GPUColor"] = (V, opts) => { if (typeof V === "object") { const method = V[SymbolIterator]; if (method !== undefined) { + // validate length of GPUColor + const length = 4; + if (V.length !== length) { + throw webidl.makeException( + TypeError, + `A sequence of number used as a GPUColor must have exactly ${length} elements.`, + opts, + ); + } return webidl.converters["sequence<double>"](V, opts); } return webidl.converters["GPUColorDict"](V, opts); |