{"record":{"id":"61fd6d2bc4393263","repo":"gchq/CyberChef","slug":"invalid-file-type-61fd6d","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/NormaliseImage.mjs","lineNumber":40,"sourceCode":"\n        this.name = \"Normalise Image\";\n        this.module = \"Image\";\n        this.description = \"Normalise the image colours.\";\n        this.infoURL = \"\";\n        this.inputType = \"ArrayBuffer\";\n        this.outputType = \"ArrayBuffer\";\n        this.presentType = \"html\";\n        this.args = [];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    async run(input, args) {\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 opening image file. (${err})`);\n        }\n\n        try {\n            image.normalize();\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);\n            }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/NormaliseImage.mjs#L22-L58","documentation":"Thrown by NormaliseImage.run when isImage(input) returns false — the input ArrayBuffer's magic bytes do not match any recognised image signature (png, jpg, gif, bmp, etc.). The operation only colour-normalises images, so non-image data is rejected before invoking Jimp.","triggerScenarios":"run(input, args) with an ArrayBuffer whose header bytes are not a known image magic number. Feeding text, a PDF, a zip, a truncated image, or an empty buffer all produce this.","commonSituations":"Wrong file dropped into the input; image with a missing/corrupted header; upstream operation outputs a byteArray or string rather than an ArrayBuffer; empty buffer from a failed fetch; file with the wrong extension but actually a different format.","solutions":["Feed an actual image file (PNG/JPG/GIF/BMP) as an ArrayBuffer.","Ensure the upstream operation outputs ArrayBuffer (e.g. use 'From Hex' or 'From Base64' before this op).","Verify the file is not truncated or zero-length."],"exampleFix":"// before: feeding a string\nchef.bake(\"Normalise Image\", [], \"not an image\");\n// after: feed decoded image bytes\nchef.bake(\"Normalise Image\", [], imageArrayBuffer);","handlingStrategy":"type-guard","validationCode":"import { isImage } from \"core/lib/FileType.mjs\";\nif (!isImage(input)) {\n  // do not call Normalise Image; provide a real image ArrayBuffer\n}","typeGuard":"const isImageBuffer = (buf) => Boolean(isImage(buf));","tryCatchPattern":"try { await chef.bake(\"Normalise Image\", [], input); }\ncatch (e) { if (e.message === \"Invalid file type.\") provideImage(); else throw e; }","preventionTips":["Confirm upstream ops emit ArrayBuffer, not string/byteArray.","Sniff the magic bytes before baking.","Reject empty buffers upstream."],"tags":["image","file-type","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}