gchq/CyberChef · error · OperationError

Error covering image. (${err})

Error message

Error covering image. (${err})

What it means

After a successful load, Cover Image runs image.cover() and then image.getBuffer() to export. Any failure in the cover/resize or the buffer export is caught and re-thrown as 'Error covering image.' The dominant preventable cause is invalid target dimensions.

Source

Thrown at src/core/operations/CoverImage.mjs:130

        }
        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) {
            throw new OperationError(`Error covering image. (${err})`);
        }
    }

    /**
     * Displays the covered image using HTML for web apps
     * @param {ArrayBuffer} data
     * @returns {html}
     */
    present(data) {
        if (!data.byteLength) return "";
        const dataArray = new Uint8Array(data);

        const type = isImage(dataArray);
        if (!type) {
            throw new OperationError("Invalid file type.");
        }

        return `<img src="data:${type};base64,${toBase64(dataArray)}">`;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Ensure Width and Height are integers >= 1 and memory-reasonable.
  2. Use a supported resizing algorithm option.
  3. Downscale very large images in stages.

Example fix

// before
const args = [0, 0, "Center", "Middle", "Bilinear"];
// after
const args = [100, 100, "Center", "Middle", "Bilinear"];
Defensive patterns

Strategy: validation

Validate before calling

function validDims(width, height) {
  return Number.isInteger(width) && Number.isInteger(height) && width >= 1 && height >= 1;
}
if (!validDims(width, height)) {
  throw new Error(`Invalid cover dimensions: width=${width}, height=${height}`);
}
const ALGS = ["Nearest Neighbour", "Bilinear", "Bicubic", "Hermite", "Bezier"];
if (!ALGS.includes(alg)) {
  throw new Error(`Unsupported resize algorithm: ${alg}`);
}

Type guard

function isCoverArgs(width, height, alg) {
  return Number.isInteger(width) && width >= 1 &&
    Number.isInteger(height) && height >= 1 &&
    ["Nearest Neighbour", "Bilinear", "Bicubic", "Hermite", "Bezier"].includes(alg);
}

Try / catch

try {
  result = await coverImage.run(input, args);
} catch (err) {
  if (/Error covering image/.test(err.message)) {
    // Most often width/height <= 0 or unsupported algorithm. Re-check args.
  }
  throw err;
}

Prevention

When it happens

Trigger: Width or height of 0 or negative; extremely large dimensions exhausting memory; an unsupported resize algorithm mapping to undefined; getBuffer encode failure.

Common situations: Recipe/script passing width=0 or height=0; oversized targets; algorithm string typo.

Related errors


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