From 543c2e73fb3400e2010f01fb0f2a414e4b9c208a Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Thu, 3 Jun 2021 11:16:26 -0400 Subject: [PATCH] Avoid mutating input buffer in crop preprocessor --- src/features/preprocessors/crop/worker/crop.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/features/preprocessors/crop/worker/crop.ts b/src/features/preprocessors/crop/worker/crop.ts index b63e6008..05d3d296 100644 --- a/src/features/preprocessors/crop/worker/crop.ts +++ b/src/features/preprocessors/crop/worker/crop.ts @@ -22,7 +22,7 @@ export default async function crop( const cols = width * 4; const newCols = newWidth * 4; - const pixels = new Uint8ClampedArray(data.buffer, 0, newHeight * newCols); + const pixels = new Uint8ClampedArray(newHeight * newCols); for (let y = 0; y < newHeight; y++) { const x = left * 4; const row = new Uint8ClampedArray( @@ -33,5 +33,5 @@ export default async function crop( pixels.set(row, y * newCols); } - return new ImageData(pixels.slice(), newWidth, newHeight); + return new ImageData(pixels, newWidth, newHeight); }