gchq/CyberChef · error · OperationError
Invalid file type.
Error message
Invalid file type.
What it means
Top-of-run guard in Image Filter: isImage(input) must return true before Jimp is invoked. Identical in intent to error 412 - the buffer's magic bytes must match a known raster image type.
Source
Thrown at src/core/operations/ImageFilter.mjs:48
this.presentType = "html";
this.args = [
{
name: "Filter type",
type: "option",
value: ["Greyscale", "Sepia"],
},
];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {byteArray}
*/
async run(input, args) {
const [filterType] = 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(
"Applying " +
filterType.toLowerCase() +
" filter to image...",
);
if (filterType === "Greyscale") {
image.greyscale();
} else {View on GitHub (pinned to 4290ea7539)
Solutions
- Confirm the input is a complete raster image (PNG/JPEG/GIF/BMP/WebP).
- Decode base64/hex input first.
- Reject empty buffers before invoking.
- Rasterise vector formats (SVG/PDF) beforehand.
Example fix
// before op.run(svgString, ["Greyscale"]); // after: rasterise then filter op.run(pngBuffer, ["Greyscale"]);
Defensive patterns
Strategy: type-guard
Validate before calling
import { isImage } from "../lib/FileType.mjs";
function assertFilterImageInput(buf) {
if (!isImage(buf)) throw new Error('Input is not a recognised image type');
} Type guard
function isFilterImageInput(buf) {
return buf instanceof ArrayBuffer ? isImage(new Uint8Array(buf)) : !!isImage(buf);
} Try / catch
try {
result = await filter.run(buf, [filterType]);
} catch (e) {
if (e instanceof OperationError && /Invalid file type/.test(e.message)) {
return null;
}
throw e;
} Prevention
- Decode base64/hex input first.
- Reject empty buffers.
- Rasterise SVG/PDF to PNG/JPEG before filtering.
When it happens
Trigger: Non-image ArrayBuffer, empty buffer, SVG, undecoded base64/hex, or a buffer whose header was stripped by a preceding operation.
Common situations: Wrong input into the filter op; forgot to From Base64; chained after an op that returned text; dropped a PDF expecting raster handling.
Related errors
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/c509a4a780832bdd.
Report an issue: GitHub.