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

  1. Re-save the source as a standard PNG or baseline JPEG.
  2. Verify file completeness and integrity.
  3. Check the bundled Jimp version's supported formats.
  4. 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

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


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/1f0f377af105ad93. Report an issue: GitHub.