gchq/CyberChef · error · OperationError
Invalid file type.
Error message
Invalid file type.
What it means
present() renders the converted output as an <img> for the web UI and re-validates it with isImage() before base64-encoding. If the converted buffer is not recognized as an image, `if (!type)` throws 'Invalid file type.' Reaching here means the transcode produced bytes isImage cannot classify.
Source
Thrown at src/core/operations/ConvertImageFormat.mjs:130
return buffer.buffer;
} catch (err) {
throw new OperationError(`Error converting image format. (${err})`);
}
}
/**
* Displays the converted 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 ConvertImageFormat;
View on GitHub (pinned to 4290ea7539)
Solutions
- Convert to a standard format (PNG/JPEG) that isImage reliably recognizes.
- Inspect the output with Detect File Type to see the actual mime.
- In the Node API, consume the ArrayBuffer directly if display isn't required.
Example fix
// before: converting to an unrecognized target, present() fails // after: target PNG so output is reliably detected recipe: [Convert Image Format (PNG)]
Defensive patterns
Strategy: type-guard
Validate before calling
import { isImage } from "src/core/lib/FileType.mjs";
const bytes = new Uint8Array(outputBuffer);
if (!isImage(bytes)) {
throw new Error("Converted output is not a recognized image; target a standard format.");
} Type guard
import { isImage } from "src/core/lib/FileType.mjs";
function isRecognizedOutput(buf) {
return isImage(buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf) !== false;
} Prevention
- Target PNG or JPEG so the converted output is reliably recognized.
- Inspect output with Detect File Type if present() fails.
- In the Node API, consume the ArrayBuffer directly and skip present().
When it happens
Trigger: Target format produced a container/mime outside isImage's recognized set; encode produced empty/garbage bytes; output mime not in the detector table.
Common situations: Converting to an obscure format; partial/failed encode that still returned a buffer; detector/table mismatch between input and output.
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/666441af2f92defe.
Report an issue: GitHub.