{"record":{"id":"e4b1dfb85de67c2c","repo":"gchq/CyberChef","slug":"invalid-input-file-type","errorCode":null,"errorMessage":"Invalid input file type.","messagePattern":"Invalid input file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/FlipImage.mjs","lineNumber":48,"sourceCode":"        this.presentType = \"html\";\n        this.args = [\n            {\n                name: \"Axis\",\n                type: \"option\",\n                value: [\"Horizontal\", \"Vertical\"],\n            },\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    async run(input, args) {\n        const [flipAxis] = args;\n        if (!isImage(input)) {\n            throw new OperationError(\"Invalid input 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        try {\n            if (isWorkerEnvironment())\n                self.sendStatusMessage(\"Flipping image...\");\n            switch (flipAxis) {\n                case \"Horizontal\":\n                    image.flip({\n                        horizontal: true,\n                        vertical: false,\n                    });\n                    break;","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FlipImage.mjs#L30-L66","documentation":"Thrown by Flip Image when isImage(input) returns a falsy value, meaning the input ArrayBuffer's magic bytes do not match any recognized image format. The operation requires a supported raster image before handing the buffer to Jimp. This is a pre-flight format check that runs before any decoding attempt.","triggerScenarios":"Passing a non-image ArrayBuffer (text, PDF, audio, executable); passing an image format Jimp/CyberChef does not recognize; passing an empty or truncated buffer whose magic bytes are missing; feeding a string when an ArrayBuffer is expected.","commonSituations":"Recipe input type mismatch (e.g. text feeding into an image op); dropping a file whose header is stripped; SVG or HEIC files which are not raster decoders CyberChef recognizes; clipboard paste of base64 text that was not first decoded to bytes.","solutions":["Ensure the upstream operation outputs an ArrayBuffer of raw image bytes (use From Base64 / From Hex first if needed).","Confirm the file is a raster format Jimp supports (PNG, JPEG, BMP, GIF, TIFF).","Check the file header is intact and not truncated.","Verify the recipe chain does not pass a string-typed output into this ArrayBuffer input."],"exampleFix":"// before: passing raw base64 text\nflip.run(base64String, ['Horizontal']) // not bytes\n// after: decode to ArrayBuffer first\nconst buf = await fromBase64Op.run(base64String, ...);\nflip.run(buf, ['Horizontal'])","handlingStrategy":"validation","validationCode":"import { isImage } from \"../lib/FileType.mjs\";\n// Confirm input is a recognized image before flipping\nif (!isImage(new Uint8Array(input))) {\n  // skip or convert; do not call flip.run()\n}","typeGuard":"function isLikelyImage(buf) {\n  return !!isImage(buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf);\n}","tryCatchPattern":"try {\n  await flip.run(input, args);\n} catch (e) {\n  if (e.type === 'OperationError' && /Invalid input file type/.test(e.message)) {\n    // input is not an image; inform user or convert\n  } else throw e;\n}","preventionTips":["Ensure upstream ops output raw image bytes (ArrayBuffer), not text.","Decode Base64/Hex input to bytes before feeding image operations.","Confirm the format is one Jimp supports (PNG/JPEG/BMP/GIF/TIFF)."],"tags":["image","jimp","file-type","input-validation","arraybuffer"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}