Handle malformed image parser errors in View Bit Plane (#2612)

This commit is contained in:
Zain Nadeem 2026-07-03 14:02:14 +05:00 committed by GitHub
parent 3104e6073f
commit 961bbab682
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View File

@ -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;

View File

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