gchq/CyberChef · error · OperationError

Error opening image file. (${err})

Error message

Error opening image file. (${err})

What it means

After isImage() accepts the input, Convert Image Format calls Jimp.read(input) to decode. If decoding fails (corrupt/truncated payload, structurally invalid image, or a format this Jimp version can't decode), the error is wrapped as 'Error opening image file.' The type sniff passed but the real decode failed.

Source

Thrown at src/core/operations/ConvertImageFormat.mjs:91

        const pngFilterMap = {
            Auto: PNGFilterType.AUTO,
            None: PNGFilterType.NONE,
            Sub: PNGFilterType.SUB,
            Up: PNGFilterType.UP,
            Average: PNGFilterType.AVERAGE,
            Paeth: PNGFilterType.PATH,
        };

        const mime = formatMap[format];

        if (!isImage(input)) {
            throw new OperationError("Invalid file format.");
        }
        let image;
        try {
            image = await Jimp.read(input);
        } catch (err) {
            throw new OperationError(`Error opening image file. (${err})`);
        }
        try {
            let buffer;
            switch (mime) {
                case JimpMime.jpeg:
                    buffer = await image.getBuffer(mime, {
                        quality: jpegQuality,
                    });
                    break;
                case JimpMime.png:
                    buffer = await image.getBuffer(mime, {
                        filterType: pngFilterMap[pngFilterType],
                        deflateLevel: pngDeflateLevel,
                    });
                    break;
                default:
                    buffer = await image.getBuffer(mime);
                    break;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Re-save the source as a standard PNG or baseline JPEG.
  2. Confirm the file is complete and uncorrupted.
  3. Check the bundled Jimp version's supported formats.
  4. Transcode exotic formats to PNG externally first.

Example fix

// before: corrupt/truncated input that isImage accepts but Jimp rejects
// 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 convertImageFormat.run(input, args);
} catch (err) {
  if (/Error opening image file/.test(err.message)) {
    // isImage passed but Jimp decode failed: corrupt/truncated or unsupported sub-format.
    // Re-export source as PNG/baseline JPEG, then retry.
  }
  throw err;
}

Prevention

When it happens

Trigger: Truncated file (valid header, incomplete body); corrupt image structure; sub-format/color space Jimp can't handle (CMYK JPEG, 16-bit PNG); Jimp version lacking the needed codec.

Common situations: Partial 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/10d4c75c3c7a3232. Report an issue: GitHub.