gchq/CyberChef · error · OperationError
Invalid file type.
Error message
Invalid file type.
What it means
Thrown by GenerateQRCode.present() when the format is PNG and isImage() cannot identify the QR code buffer as a recognized image format. present() runs on the operation's PNG output, so this means the PNG bytes were not recognized — implying truncated or corrupted output from the encoding step.
Source
Thrown at src/core/operations/GenerateQRCode.mjs:83
const [format, size, margin, errorCorrection] = args;
return generateQrCode(input, format, size, margin, errorCorrection);
}
/**
* Displays the QR image using HTML for web apps
*
* @param {ArrayBuffer} data
* @returns {html}
*/
present(data, args) {
if (!data.byteLength && !data.length) return "";
const dataArray = new Uint8Array(data),
[format] = args;
if (format === "PNG") {
const type = isImage(dataArray);
if (!type) {
throw new OperationError("Invalid file type.");
}
return `<img src="data:${type};base64,${toBase64(dataArray)}">`;
}
return Utils.arrayBufferToStr(data);
}
}
export default GenerateQRCode;
View on GitHub (pinned to 4290ea7539)
Solutions
- Ensure the QR code input string is non-empty and within the QR capacity for the selected error-correction level.
- Use SVG format to bypass the image-type check if PNG encoding is problematic.
- Verify the buffer has PNG magic bytes (\x89PNG) before present().
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 (format === "PNG" && !isPng) {
// use SVG format or fix the upstream QR generation
} Type guard
function looksLikePng(buf) {
return buf.length >= 4 && buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47;
} Prevention
- Ensure the QR input fits the capacity for the chosen error-correction level.
- Use SVG format to bypass the PNG image-type check.
When it happens
Trigger: The QR encoder returned a non-PNG or malformed buffer, or present() receives data that has been altered between run() and present(). SVG format bypasses this check.
Common situations: An empty/failed QR generation upstream, or chaining through an operation that corrupts bytes before present().
Related errors
- Invalid file type.
- Invalid file type.
- Invalid file type.
- No padding requested but input is not a ${blockSize}-byte mu
- Unknown padding type: ${padding}
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/98716d7235b67f06.
Report an issue: GitHub.