gchq/CyberChef · error · OperationError

Invalid file type.

Error message

Invalid file type.

What it means

In web apps InvertImage.present() re-runs isImage on the bytes it received and throws if they are not a recognized image (empty buffers return '' earlier). Indicates the presented data is not an image.

Source

Thrown at src/core/operations/InvertImage.mjs:78

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

    /**
     * Displays the inverted 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 InvertImage;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Make present() only receive a successful run() output.
  2. Treat a present() failure as a run() failure and inspect leading bytes.
  3. Re-encode run output to PNG before presenting.

Example fix

// before
invertOp.present(textBuffer); // throws
// after
import { isImage } from "src/core/lib/FileType.mjs";
const out = invertOp.run(pngBuffer, []);
if (isImage(new Uint8Array(out)) === false) return '';
invertOp.present(out);
Defensive patterns

Strategy: validation

Validate before calling

import { isImage } from "src/core/lib/FileType.mjs";
function safePresent(op, data) {
  if (!data || !data.byteLength) return '';
  if (isImage(new Uint8Array(data)) === false) return '';
  return op.present(data);
}

Type guard

import { isImage } from "src/core/lib/FileType.mjs";
function isPresentableImage(data) {
  return data?.byteLength > 0 && typeof isImage(new Uint8Array(data)) === 'string';
}

Prevention

When it happens

Trigger: present() receives non-image bytes: an upstream error replaced run()'s output, present() was called directly with arbitrary data, or getBuffer produced an atypical header.

Common situations: presentType wiring feeding an error buffer to present(); manual calls in tests; an encode path with a header isImage does not recognize.

Related errors


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