{"record":{"id":"5e2ee5b983d4eb52","repo":"gchq/CyberChef","slug":"invalid-file-type-5e2ee5","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/RotateImage.mjs","lineNumber":50,"sourceCode":"        this.args = [\n            {\n                name: \"Rotation amount (degrees)\",\n                type: \"number\",\n                value: 90,\n            },\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    async run(input, args) {\n        const [degrees] = args;\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        try {\n            if (isWorkerEnvironment())\n                self.sendStatusMessage(\"Rotating image...\");\n            image.rotate(degrees);\n\n            let imageBuffer;\n            if (image.mime === \"image/gif\") {\n                imageBuffer = await image.getBuffer(JimpMime.png);\n            } else {\n                imageBuffer = await image.getBuffer(image.mime);","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/RotateImage.mjs#L32-L68","documentation":"Thrown at the top of RotateImage.run() when isImage(input) returns falsy, meaning the input ArrayBuffer's magic bytes are not a recognised image type. This guard runs before Jimp.read() so non-image input is rejected cheaply.","triggerScenarios":"Passing a text, archive, audio, or other non-image ArrayBuffer to Rotate Image; passing an image format FileType detection does not support.","commonSituations":"Feeding the wrong operation output into Rotate Image; a recipe where an upstream decode fails silently leaving non-image bytes; obscure image formats not in the FileType signature table.","solutions":["Confirm the input is a supported image (PNG, JPEG, GIF, BMP, TIFF, WebP) using a hex viewer or the 'Detect File Type' operation.","Insert a 'Render Image' or 'Detect File Type' step before Rotate Image to verify the buffer.","Convert the source to PNG/JPEG before rotating if it is an unsupported but valid image format."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { isImage } from \"src/core/lib/FileType.mjs\";\nfunction ensureImage(buf) {\n  const arr = buf instanceof Uint8Array ? buf : new Uint8Array(buf);\n  if (!isImage(arr)) throw new TypeError(\"Input is not a recognised image type\");\n  return buf;\n}","typeGuard":"function isImageInput(buf) {\n  return buf instanceof ArrayBuffer && isImage(new Uint8Array(buf)) !== null;\n}","tryCatchPattern":null,"preventionTips":["Run 'Detect File Type' before Rotate Image to confirm the magic bytes.","Convert the source to PNG/JPEG if it is an unsupported but valid image format."],"tags":["image","file-type","operation","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}