{"record":{"id":"09240bba326d08d8","repo":"gchq/CyberChef","slug":"invalid-input-file-format","errorCode":null,"errorMessage":"Invalid input file format.","messagePattern":"Invalid input file format\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/InvertImage.mjs","lineNumber":41,"sourceCode":"\n        this.name = \"Invert Image\";\n        this.module = \"Image\";\n        this.description = \"Invert the colours of an image.\";\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 input file format.\");\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(\"Inverting image...\");\n            image.invert();\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":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/InvertImage.mjs#L23-L59","documentation":"Thrown at the top of InvertImage.run() because isImage(input) returned falsy. Same mechanism as the other image ops, but the message text reads 'Invalid input file format.' (a wording inconsistency vs the usual 'Invalid file type.'). OperationError surfaced as step output.","triggerScenarios":"run(input, args) receives an ArrayBuffer whose leading bytes are not a recognized image signature: text, hex, a non-image binary, or an unsupported image format.","commonSituations":"Pasting non-image data, wrong input-format selector, chaining after a non-image step, or a modern format (AVIF/HEIC) absent from isImage's DB.","solutions":["Confirm the input is an image with 'Detect File Type'.","Ensure the prior step outputs an image ArrayBuffer.","Match the op input type to the real data.","Convert the source to PNG/JPEG upstream."],"exampleFix":"// before\ninvertOp.run(new TextEncoder().encode('nope').buffer, []); // throws 'Invalid input file format.'\n// after\nimport { isImage } from \"src/core/lib/FileType.mjs\";\nif (isImage(pngBuffer) === false) throw new Error('feed an image');\ninvertOp.run(pngBuffer, []);","handlingStrategy":"validation","validationCode":"import { isImage } from \"src/core/lib/FileType.mjs\";\nconst buf8 = input instanceof Uint8Array ? input : new Uint8Array(input);\nif (isImage(buf8) === false) {\n  throw new Error('Input is not a recognized image; cannot run invert op.');\n}","typeGuard":"import { isImage } from \"src/core/lib/FileType.mjs\";\nfunction isImageBuffer(buf) {\n  const u8 = buf instanceof Uint8Array ? buf : new Uint8Array(buf);\n  return typeof isImage(u8) === 'string';\n}","tryCatchPattern":null,"preventionTips":["Probe with isImage() before invoking invert.","Confirm upstream output is an image ArrayBuffer.","Keep the input-format selector in sync with the data.","Convert exotic formats to PNG upstream."],"tags":["image","cyberchef","input-validation","file-format","jimp"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}