{"record":{"id":"4356e6a0f4a4d434","repo":"gchq/CyberChef","slug":"invalid-file-type-4356e6","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ImageOpacity.mjs","lineNumber":50,"sourceCode":"            {\n                name: \"Opacity (%)\",\n                type: \"number\",\n                value: 100,\n                min: 0,\n                max: 100,\n            },\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    async run(input, args) {\n        const [opacity] = 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(\"Changing image opacity...\");\n            image.opacity(opacity / 100);\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/ImageOpacity.mjs#L32-L68","documentation":"Thrown at the top of ImageOpacity.run() because isImage(input) returned falsy before Jimp is invoked. Identical mechanism to the other image ops: the buffer's leading bytes are not a recognized image signature. OperationError, so it becomes the step output.","triggerScenarios":"run(input, args) receives an ArrayBuffer that is text, hex, a non-image binary, or an image format not in the signature DB. Also when the upstream step did not output an image ArrayBuffer.","commonSituations":"Pasting non-image data, wrong input-format selector, or chaining after an op whose output is not an image. Modern formats (AVIF/HEIC) not detected by isImage also trigger it.","solutions":["Confirm the input is an image with 'Detect File Type'.","Ensure the prior recipe step outputs an image ArrayBuffer.","Match the op input type to the real data format.","Convert the source to PNG/JPEG upstream if the format is unsupported."],"exampleFix":"// before\nopacityOp.run(new TextEncoder().encode('nope').buffer, [50]); // throws\n// after\nimport { isImage } from \"src/core/lib/FileType.mjs\";\nif (isImage(pngBuffer) === false) throw new Error('feed an image');\nopacityOp.run(pngBuffer, [50]);","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 opacity 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 the opacity op.","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"}