fix: harden generate image mode validation

This commit is contained in:
Кирилл Ветров 2026-06-25 14:11:19 +03:00
parent 64b63d86bc
commit 32a9024938

View File

@ -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}`,