gchq/CyberChef · error · OperationError
Invalid file type.
Error message
Invalid file type.
What it means
Thrown by GenerateImage.present() when isImage() cannot identify the generated buffer as a known image format. present() runs on the output of run() (which produces a PNG), so this indicates the PNG buffer was not recognized — implying the encoding step produced invalid or empty data even though it did not throw.
Source
Thrown at src/core/operations/GenerateImage.mjs:196
const result = await image.getBuffer(JimpMime.png);
return result.buffer.slice(result.byteOffset, result.byteOffset + result.byteLength);
} catch (err) {
throw new OperationError(`Error generating image. (${err})`);
}
}
/**
* Displays the generated 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 GenerateImage;
View on GitHub (pinned to 4290ea7539)
Solutions
- Ensure present() receives the direct ArrayBuffer output of run() without intermediate corruption.
- If the buffer is empty, note that present() returns '' for empty data rather than throwing.
- Verify the upstream run() produced valid PNG bytes by checking the magic header (\x89PNG).
Defensive patterns
Strategy: validation
Validate before calling
const PNG_MAGIC = [0x89, 0x50, 0x4e, 0x47];
const isPng = data.length >= 4 && PNG_MAGIC.every((b, i) => data[i] === b);
if (!isPng) {
// do not pass to present(); the buffer is not a valid PNG
} Type guard
function looksLikePng(buf) {
return buf.length >= 4 && buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47;
} Prevention
- Feed present() only the direct ArrayBuffer output of run().
- Avoid chaining byte-altering operations between run() and present().
When it happens
Trigger: run() returned a buffer that is not a valid PNG (truncated, wrong magic bytes), or present() is called directly with arbitrary non-image data. A zero-length buffer is short-circuited earlier, so this is for non-empty-but-unrecognized data.
Common situations: Chaining GenerateImage output through another operation that corrupts bytes before present() runs, or calling present() on hand-supplied data in a custom recipe.
Related errors
- Invalid file type.
- Invalid file type.
- Invalid file type.
- Invalid file type.
- Error blurring image. (${err})
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/7e01491253fe9696.
Report an issue: GitHub.