fix: harden generate image mode validation
This commit is contained in:
parent
64b63d86bc
commit
32a9024938
@ -74,12 +74,12 @@ class GenerateImage extends Operation {
|
|||||||
Bits: 1 / 8,
|
Bits: 1 / 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
const bytesPerPixel = bytePerPixelMap[mode];
|
if (!Object.hasOwn(bytePerPixelMap, mode)) {
|
||||||
|
|
||||||
if (bytesPerPixel === undefined) {
|
|
||||||
throw new OperationError(`Unsupported Mode: (${mode})`);
|
throw new OperationError(`Unsupported Mode: (${mode})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bytesPerPixel = bytePerPixelMap[mode];
|
||||||
|
|
||||||
if (bytesPerPixel > 0 && input.length % bytesPerPixel !== 0) {
|
if (bytesPerPixel > 0 && input.length % bytesPerPixel !== 0) {
|
||||||
throw new OperationError(
|
throw new OperationError(
|
||||||
`Number of bytes is not a divisor of ${bytesPerPixel}`,
|
`Number of bytes is not a divisor of ${bytesPerPixel}`,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user