gchq/CyberChef · error · OperationError
Error loading image. (${err})
Error message
Error loading image. (${err}) What it means
After isImage() accepts the input, Cover Image calls Jimp.read(input) to decode. If decoding fails (corrupt/truncated data, structurally invalid image, or a format this Jimp version can't read), the error is wrapped as 'Error loading image.' The type sniff passed but the actual decode did not.
Source
Thrown at src/core/operations/CoverImage.mjs:111
const alignMap = {
Left: HorizontalAlign.LEFT,
Center: HorizontalAlign.CENTER,
Right: HorizontalAlign.RIGHT,
Top: VerticalAlign.TOP,
Middle: VerticalAlign.MIDDLE,
Bottom: VerticalAlign.BOTTOM,
};
if (!isImage(input)) {
throw new OperationError("Invalid file type.");
}
let image;
try {
image = await Jimp.read(input);
} catch (err) {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (isWorkerEnvironment())
self.sendStatusMessage("Covering image...");
image.cover({
w: width,
h: height,
align: alignMap[hAlign] | alignMap[vAlign],
mode: resizeMap[alg],
});
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) {View on GitHub (pinned to 4290ea7539)
Solutions
- Re-save the source as a standard PNG or baseline JPEG.
- Verify file completeness and integrity.
- Check the bundled Jimp version's supported formats.
- Transcode exotic formats to PNG externally first.
Example fix
// before: header-valid but body-corrupt input // after: supply a complete, valid image file
Defensive patterns
Strategy: try-catch
Validate before calling
import { isImage } from "src/core/lib/FileType.mjs";
// Reduces (not eliminates) the chance before Jimp.read.
const bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : input;
if (!isImage(bytes)) {
throw new Error("Not a recognized image — Jimp.read would likely fail.");
} Type guard
import { isImage } from "src/core/lib/FileType.mjs";
function isLikelyDecodableImage(buf) {
const bytes = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;
return isImage(bytes) !== false;
} Try / catch
try {
result = await coverImage.run(input, args);
} catch (err) {
if (/Error loading image/.test(err.message)) {
// isImage passed but Jimp decode failed: re-export source as PNG/baseline JPEG, then retry.
}
throw err;
} Prevention
- isImage passing does not guarantee Jimp can decode — verify integrity separately.
- Prefer standard PNG/baseline JPEG sources.
- Re-test supported formats after any Jimp upgrade.
When it happens
Trigger: Truncated payload; valid header but broken body; sub-format/color space Jimp can't decode; Jimp version lacking the codec.
Common situations: Incomplete download; exotic re-exported variant; dependency upgrade changing supported formats.
Related errors
- Error loading image. (${err})
- Error opening image file. (${err})
- Error loading image. (${err})
- Invalid file type.
- Error containing image. (${err})
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/1f0f377af105ad93.
Report an issue: GitHub.