gchq/CyberChef · error · OperationError

Invalid file type.

Error message

Invalid file type.

What it means

AddTextToImage runs isImage(input) (a magic-byte check against common image signatures) and refuses non-image input before handing the data to Jimp. This guards against feeding arbitrary text/binary into an image pipeline. The error fires inside run() at the start of processing.

Source

Thrown at src/core/operations/AddTextToImage.mjs:127

     * @param {Object[]} args
     * @returns {byteArray}
     */
    async run(input, args) {
        const text = args[0],
            hAlign = args[1],
            vAlign = args[2],
            size = args[5],
            fontFace = args[6],
            red = args[7],
            green = args[8],
            blue = args[9],
            alpha = args[10];

        let xPos = args[3],
            yPos = args[4];

        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})`);
        }

        if (isWorkerEnvironment())
            self.sendStatusMessage("Adding text to image...");

        const fontsMap = {};
        try {
            const fonts = [
                import(
                    /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/Roboto72White.fnt"
                ),

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Ensure the input is a real, decoded image file (not Base64 text — run From Base64 first if needed).
  2. Use a File-type input rather than a string where the recipe allows.
  3. Validate with isImage before the operation in your own pipeline.

Example fix

// before: input = "iVBORw0KG..." (base64 text) → 'Invalid file type.'
// after: decode first
input = base64ToBytes(base64Text); // then AddTextToImage
Defensive patterns

Strategy: type-guard

Validate before calling

import { isImage } from '../lib/FileType.mjs';
function ensureImage(bytes) {
  if (!isImage(new Uint8Array(bytes))) {
    throw new Error('Input is not a recognized image format');
  }
}

Type guard

function isImageBytes(bytes) { return !!isImage(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes)); }

Try / catch

try { addTextToImage(input, ...); } catch (e) { if (/Invalid file type/.test(e.message)) {/* decode/convert input to a real image */} else throw e; }

Prevention

When it happens

Trigger: The input ArrayBuffer/bytes do not begin with a recognized image signature (PNG/JPEG/GIF/BMP/WebP etc.). E.g. feeding a text file, a JSON blob, a PDF, or already-Base64 text rather than decoded image bytes.

Common situations: Upstream operation output is not an image; the user chained the op onto the wrong data; input was Base64 and not decoded first; a corrupt/truncated file whose magic bytes are missing.

Related errors


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