gchq/CyberChef · error · OperationError
Invalid file type.
Error message
Invalid file type.
What it means
Crop Image performs a manual crop (x, y, width, height) or an autocrop. It validates the input via isImage() first; non-image bytes cause `if (!isImage(input))` to throw 'Invalid file type.' This is the magic-byte input check before Jimp decoding.
Source
Thrown at src/core/operations/CropImage.mjs:107
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
*/
async run(input, args) {
const [
xPos,
yPos,
width,
height,
autocrop,
autoTolerance,
autoFrames,
autoSymmetric,
autoBorder,
] = args;
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})`);
}
try {
if (isWorkerEnvironment())
self.sendStatusMessage("Cropping image...");
if (autocrop) {
image.autocrop({
tolerance: autoTolerance / 100,
cropOnlyFrames: autoFrames,
cropSymmetric: autoSymmetric,
leaveBorder: autoBorder,
});View on GitHub (pinned to 4290ea7539)
Solutions
- Supply a raw image ArrayBuffer isImage recognizes.
- Decode hex/base64 input with From Hex / From Base64 first.
- Confirm with Detect File Type before cropping.
Example fix
// before: passing hex text directly input = "89504e47..."; // after recipe: [From Hex, Crop Image]
Defensive patterns
Strategy: type-guard
Validate before calling
import { isImage } from "src/core/lib/FileType.mjs";
const bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : input;
if (!isImage(bytes)) {
throw new Error("Input is not a recognized image; supply raw image bytes.");
} Type guard
import { isImage } from "src/core/lib/FileType.mjs";
function isImageInput(buf) {
const bytes = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;
return isImage(bytes) !== false;
} Prevention
- Feed raw image bytes; decode hex/base64 first.
- Use Detect File Type to confirm the input is an image.
- Confirm the format is in isImage's recognized signature table.
When it happens
Trigger: Non-image bytes; truncated file missing magic bytes; empty ArrayBuffer; a format absent from isImage's signature table; passing a string instead of raw bytes.
Common situations: Wrong input; chaining after a non-image-producing op; forgetting to decode hex/base64; unsupported image format.
Related errors
- Invalid file type.
- Invalid file format.
- Invalid file type.
- Invalid file type.
- Error loading image. (${err})
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/861bcfb443650256.
Report an issue: GitHub.