From dc026bf9a285d8ba3f6a6aa19ed36f95cb3d6d52 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 28 Aug 2026 23:33:32 -0700 Subject: [PATCH] Fix buffer slicing when normalizing. --- src/lib/wasm.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/wasm.ts b/src/lib/wasm.ts index f08d3d1..37bdbb4 100644 --- a/src/lib/wasm.ts +++ b/src/lib/wasm.ts @@ -124,10 +124,13 @@ export function normalize (name: string, byteLengthMin: number, byteLengthMax: n return new Uint8Array(value.match(/[0-9a-f]{2}/gi)?.map(b => parseInt(b, 16)) || []) } - if (!(value instanceof ArrayBuffer || value instanceof Uint8Array)) { + if (value instanceof ArrayBuffer) { + value = new Uint8Array(value) + } + if (!(value instanceof Uint8Array)) { throw new TypeError(`${name} must be Uint8Array or ArrayBuffer`) } - const bytes = new Uint8Array(value.slice()) + const bytes = value.slice() if (bytes.byteLength < byteLengthMin) { throw new TypeError(`${name} must be at least ${byteLengthMin} bytes`) } -- 2.52.0