{"record":{"id":"25f1b11fa4207964","repo":"gchq/CyberChef","slug":"invalid-file-type","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/AddTextToImage.mjs","lineNumber":127,"sourceCode":"     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    async run(input, args) {\n        const text = args[0],\n            hAlign = args[1],\n            vAlign = args[2],\n            size = args[5],\n            fontFace = args[6],\n            red = args[7],\n            green = args[8],\n            blue = args[9],\n            alpha = args[10];\n\n        let xPos = args[3],\n            yPos = args[4];\n\n        if (!isImage(input)) {\n            throw new OperationError(\"Invalid file type.\");\n        }\n\n        let image;\n        try {\n            image = await Jimp.read(input);\n        } catch (err) {\n            throw new OperationError(`Error loading image. (${err})`);\n        }\n\n        if (isWorkerEnvironment())\n            self.sendStatusMessage(\"Adding text to image...\");\n\n        const fontsMap = {};\n        try {\n            const fonts = [\n                import(\n                    /* webpackMode: \"eager\" */ \"../../web/static/fonts/bmfonts/Roboto72White.fnt\"\n                ),","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/AddTextToImage.mjs#L109-L145","documentation":"AddTextToImage runs isImage(input) (a magic-byte check against common image signatures) and refuses non-image input before handing the data to Jimp. This guards against feeding arbitrary text/binary into an image pipeline. The error fires inside run() at the start of processing.","triggerScenarios":"The input ArrayBuffer/bytes do not begin with a recognized image signature (PNG/JPEG/GIF/BMP/WebP etc.). E.g. feeding a text file, a JSON blob, a PDF, or already-Base64 text rather than decoded image bytes.","commonSituations":"Upstream operation output is not an image; the user chained the op onto the wrong data; input was Base64 and not decoded first; a corrupt/truncated file whose magic bytes are missing.","solutions":["Ensure the input is a real, decoded image file (not Base64 text — run From Base64 first if needed).","Use a File-type input rather than a string where the recipe allows.","Validate with isImage before the operation in your own pipeline."],"exampleFix":"// before: input = \"iVBORw0KG...\" (base64 text) → 'Invalid file type.'\n// after: decode first\ninput = base64ToBytes(base64Text); // then AddTextToImage","handlingStrategy":"type-guard","validationCode":"import { isImage } from '../lib/FileType.mjs';\nfunction ensureImage(bytes) {\n  if (!isImage(new Uint8Array(bytes))) {\n    throw new Error('Input is not a recognized image format');\n  }\n}","typeGuard":"function isImageBytes(bytes) { return !!isImage(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes)); }","tryCatchPattern":"try { addTextToImage(input, ...); } catch (e) { if (/Invalid file type/.test(e.message)) {/* decode/convert input to a real image */} else throw e; }","preventionTips":["Decode Base64 to bytes before feeding image ops.","Pass real image files, not text representations.","Validate with isImage in your pipeline before invoking."],"tags":["image","jimp","validation","file-type"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}