{"record":{"id":"c509a4a780832bdd","repo":"gchq/CyberChef","slug":"invalid-file-type-c509a4","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ImageFilter.mjs","lineNumber":48,"sourceCode":"        this.presentType = \"html\";\n        this.args = [\n            {\n                name: \"Filter type\",\n                type: \"option\",\n                value: [\"Greyscale\", \"Sepia\"],\n            },\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    async run(input, args) {\n        const [filterType] = 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 loading image. (${err})`);\n        }\n        try {\n            if (isWorkerEnvironment())\n                self.sendStatusMessage(\n                    \"Applying \" +\n                        filterType.toLowerCase() +\n                        \" filter to image...\",\n                );\n            if (filterType === \"Greyscale\") {\n                image.greyscale();\n            } else {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ImageFilter.mjs#L30-L66","documentation":"Top-of-run guard in Image Filter: isImage(input) must return true before Jimp is invoked. Identical in intent to error 412 - the buffer's magic bytes must match a known raster image type.","triggerScenarios":"Non-image ArrayBuffer, empty buffer, SVG, undecoded base64/hex, or a buffer whose header was stripped by a preceding operation.","commonSituations":"Wrong input into the filter op; forgot to From Base64; chained after an op that returned text; dropped a PDF expecting raster handling.","solutions":["Confirm the input is a complete raster image (PNG/JPEG/GIF/BMP/WebP).","Decode base64/hex input first.","Reject empty buffers before invoking.","Rasterise vector formats (SVG/PDF) beforehand."],"exampleFix":"// before\nop.run(svgString, [\"Greyscale\"]);\n// after: rasterise then filter\nop.run(pngBuffer, [\"Greyscale\"]);","handlingStrategy":"type-guard","validationCode":"import { isImage } from \"../lib/FileType.mjs\";\nfunction assertFilterImageInput(buf) {\n  if (!isImage(buf)) throw new Error('Input is not a recognised image type');\n}","typeGuard":"function isFilterImageInput(buf) {\n  return buf instanceof ArrayBuffer ? isImage(new Uint8Array(buf)) : !!isImage(buf);\n}","tryCatchPattern":"try {\n  result = await filter.run(buf, [filterType]);\n} catch (e) {\n  if (e instanceof OperationError && /Invalid file type/.test(e.message)) {\n    return null;\n  }\n  throw e;\n}","preventionTips":["Decode base64/hex input first.","Reject empty buffers.","Rasterise SVG/PDF to PNG/JPEG before filtering."],"tags":["image","jimp","file-type","magic-bytes","argument-validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}