{"record":{"id":"434d9d126494fb98","repo":"gchq/CyberChef","slug":"invalid-file-type-434d9d","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ParseQRCode.mjs","lineNumber":52,"sourceCode":"            },\n        ];\n        // No Magic checks: detecting a QR code in arbitrary image data requires\n        // actually attempting to parse one, which is expensive and produces\n        // spurious \"Could not read a QR code from the image\" log messages for\n        // any image input via Magic. Users can add Parse QR Code manually when\n        // they know the image contains a QR code. See issue #2610.\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    async run(input, args) {\n        const [normalise] = args;\n\n        if (!isImage(input)) {\n            throw new OperationError(\"Invalid file type.\");\n        }\n        return parseQrCode(input, normalise);\n    }\n}\n\nexport default ParseQRCode;\n","sourceCodeStart":34,"sourceCodeEnd":59,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ParseQRCode.mjs#L34-L59","documentation":"The Parse QR Code operation checks the input ArrayBuffer's magic bytes via isImage(). If the data does not have a recognized image file signature (PNG, JPEG, GIF, BMP, etc.), it is rejected before any QR-decode attempt is made.","triggerScenarios":"Input is not an image: plain text, raw bytes, a PDF, a JSON payload, or binary data of any non-image type. Also fires for a truncated or corrupted image whose magic bytes were stripped. The input type must be ArrayBuffer.","commonSituations":"User feeds a text string or hex data instead of an image file. User provides a file that is a PDF or SVG containing a QR code (the operation needs a raster image). The image data was truncated during upload or copy, losing the header.","solutions":["Provide a recognized raster image format (PNG, JPEG, GIF, BMP) as an ArrayBuffer","Convert SVG or PDF-embedded QR codes to a raster image first","Ensure the input reaches the operation as ArrayBuffer, not as a string"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check: verify the input is a recognized image type by magic bytes\nfunction getImageType(buf) {\n  const bytes = new Uint8Array(buf.slice(0, 8));\n  if (bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4E && bytes[3] === 0x47) return 'PNG';\n  if (bytes[0] === 0xFF && bytes[1] === 0xD8 && bytes[2] === 0xFF) return 'JPEG';\n  if (bytes[0] === 0x47 && bytes[1] === 0x49 && bytes[2] === 0x46) return 'GIF';\n  if (bytes[0] === 0x42 && bytes[1] === 0x4D) return 'BMP';\n  return null;\n}\nif (!getImageType(input)) {\n  throw new Error(\"Input is not a recognized image format (PNG, JPEG, GIF, BMP).\");\n}","typeGuard":"function isImageBuffer(buf) {\n  return buf instanceof ArrayBuffer && getImageType(buf) !== null;\n}","tryCatchPattern":"try {\n  const result = await chef.parseQRCode(input, [false]);\n} catch (e) {\n  if (/Invalid file type/i.test(e.message)) {\n    console.error(\"Provide a raster image (PNG/JPEG/GIF/BMP) as ArrayBuffer\");\n  } else { throw e; }\n}","preventionTips":["Convert PDF or SVG QR codes to a raster image before parsing","Ensure the input reaches the operation as ArrayBuffer, not a string","Verify the image file is not truncated (magic bytes intact)"],"tags":["qr-code","image","file-type","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}