gchq/CyberChef · warning · OperationError

Invalid file type.

Error message

Invalid file type.

What it means

Thrown in the present() method when isImage() returns falsy on the operation's output buffer. present() renders the flipped image as an HTML <img> tag and must confirm the output is still a recognizable image type. In normal flow this is defensive: run() just produced image bytes, so this fires mainly when the output buffer is empty or somehow not image-typed.

Source

Thrown at src/core/operations/FlipImage.mjs:98

            }
            return imageBuffer.buffer;
        } catch (err) {
            throw new OperationError(`Error flipping image. (${err})`);
        }
    }

    /**
     * Displays the flipped 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)}">`;
    }
}

export default FlipImage;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Inspect the output ArrayBuffer from run() to confirm it has valid image magic bytes.
  2. Ensure no downstream op mutates the buffer before present() is called.
  3. If reproducing in Node (no present path), note present() only runs in the browser UI.
Defensive patterns

Strategy: validation

Validate before calling

import { isImage } from "../lib/FileType.mjs";
// present() only runs in the browser; guard the buffer before rendering
const arr = new Uint8Array(data);
if (!arr.byteLength || !isImage(arr)) return ''; // skip rendering instead of throwing

Type guard

function isPresentableImage(buf) {
  const arr = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;
  return arr.byteLength > 0 && !!isImage(arr);
}

Prevention

When it happens

Trigger: The flipped output buffer has no detectable image magic bytes; data.byteLength is non-zero but the bytes are not a valid image header (e.g. an upstream op returned garbage); an empty/zero-length buffer that bypassed the byteLength guard by being non-zero but corrupt.

Common situations: Chaining ops where an intermediate step corrupts the buffer; a custom present path invoked on stale/modified data; edge cases where Jimp getBuffer returned incomplete bytes.

Related errors


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