From 32a9024938382f400c070ddc6e899ee37b74d4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=92=D0=B5=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= Date: Thu, 25 Jun 2026 14:11:19 +0300 Subject: [PATCH] fix: harden generate image mode validation --- src/core/operations/GenerateImage.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/operations/GenerateImage.mjs b/src/core/operations/GenerateImage.mjs index 56b5798a..c276213d 100644 --- a/src/core/operations/GenerateImage.mjs +++ b/src/core/operations/GenerateImage.mjs @@ -74,12 +74,12 @@ class GenerateImage extends Operation { Bits: 1 / 8, }; - const bytesPerPixel = bytePerPixelMap[mode]; - - if (bytesPerPixel === undefined) { + if (!Object.hasOwn(bytePerPixelMap, mode)) { throw new OperationError(`Unsupported Mode: (${mode})`); } + const bytesPerPixel = bytePerPixelMap[mode]; + if (bytesPerPixel > 0 && input.length % bytesPerPixel !== 0) { throw new OperationError( `Number of bytes is not a divisor of ${bytesPerPixel}`,