Handle malformed image parser errors in View Bit Plane (#2612)
This commit is contained in:
parent
3104e6073f
commit
961bbab682
@ -52,9 +52,15 @@ class ViewBitPlane extends Operation {
|
||||
if (!isImage(input))
|
||||
throw new OperationError("Please enter a valid image file.");
|
||||
|
||||
const [colour, bit] = args,
|
||||
parsedImage = await Jimp.read(input),
|
||||
width = parsedImage.bitmap.width,
|
||||
const [colour, bit] = args;
|
||||
let parsedImage;
|
||||
try {
|
||||
parsedImage = await Jimp.read(input);
|
||||
} catch (err) {
|
||||
throw new OperationError(`Error loading image. (${err})`);
|
||||
}
|
||||
|
||||
const width = parsedImage.bitmap.width,
|
||||
height = parsedImage.bitmap.height,
|
||||
colourIndex = COLOUR_OPTIONS.indexOf(colour),
|
||||
bitIndex = 7 - bit;
|
||||
|
||||
@ -241,6 +241,21 @@ TestRegister.addTests([
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "View Bit Plane: malformed PNG",
|
||||
input: PNG_HEX.replace("49484452", "49424452"),
|
||||
expectedOutput: "Error loading image. (Error: unrecognised content at end of stream)",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "View Bit Plane",
|
||||
args: ["Red", 0]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Randomize Colour Palette",
|
||||
"input": PNG_HEX,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user