gchq/CyberChef · error · OperationError
Error loading image. (${err})
Error message
Error loading image. (${err}) What it means
Wraps any failure of Jimp.read(input) inside InvertImage.run(). The magic bytes passed isImage but Jimp could not decode the body. The original error is interpolated. OperationError surfaced as step output.
Source
Thrown at src/core/operations/InvertImage.mjs:48
this.presentType = "html";
this.args = [];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
*/
async run(input, args) {
if (!isImage(input)) {
throw new OperationError("Invalid input file format.");
}
let image;
try {
image = await Jimp.read(input);
} catch (err) {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (isWorkerEnvironment())
self.sendStatusMessage("Inverting image...");
image.invert();
let imageBuffer;
if (image.mime === "image/gif") {
imageBuffer = await image.getBuffer(JimpMime.png);
} else {
imageBuffer = await image.getBuffer(image.mime);
}
return imageBuffer.buffer;
} catch (err) {
throw new OperationError(`Error inverting image. (${err})`);
}
}
View on GitHub (pinned to 4290ea7539)
Solutions
- Read ${err} for Jimp's specific reason.
- Re-save the source as PNG or JPEG and retry.
- Confirm buffer length matches declared dimensions.
- Verify jimp supports the codec.
Example fix
// before invertOp.run(truncatedPng, []); // -> Error loading image. // after const buf = await reencodeToPng(truncatedPng); invertOp.run(buf, []);
Defensive patterns
Strategy: try-catch
Try / catch
try {
await invertOp.run(buf, []);
} catch (e) {
if (e instanceof OperationError && /Error loading image/.test(e.message)) {
reportCorruptImage(e.message);
} else throw e;
} Prevention
- Re-encode untrusted images to PNG first.
- Validate buffer length against the header.
- Pin a known-good jimp version.
- Surface Jimp's interpolated reason.
When it happens
Trigger: isImage accepted the signature but Jimp rejects the payload: truncated file, corrupt body, or a codec Jimp lacks. An ArrayBuffer shorter than the header implies is common.
Common situations: Truncated copy-paste, browser-renderable but Jimp-undecodable images, jimp version skew, valid signature around unrelated bytes.
Related errors
- Error loading image. (${err})
- Error loading image. (${err})
- Error adjusting image hue / saturation / lightness. (${err})
- Error changing image opacity. (${err})
- Error inverting image. (${err})
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/e47acec2b5681e97.
Report an issue: GitHub.