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))
|
if (!isImage(input))
|
||||||
throw new OperationError("Please enter a valid image file.");
|
throw new OperationError("Please enter a valid image file.");
|
||||||
|
|
||||||
const [colour, bit] = args,
|
const [colour, bit] = args;
|
||||||
parsedImage = await Jimp.read(input),
|
let parsedImage;
|
||||||
width = parsedImage.bitmap.width,
|
try {
|
||||||
|
parsedImage = await Jimp.read(input);
|
||||||
|
} catch (err) {
|
||||||
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const width = parsedImage.bitmap.width,
|
||||||
height = parsedImage.bitmap.height,
|
height = parsedImage.bitmap.height,
|
||||||
colourIndex = COLOUR_OPTIONS.indexOf(colour),
|
colourIndex = COLOUR_OPTIONS.indexOf(colour),
|
||||||
bitIndex = 7 - bit;
|
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",
|
name: "Randomize Colour Palette",
|
||||||
"input": PNG_HEX,
|
"input": PNG_HEX,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user