{"record":{"id":"56a5bdc292fafc74","repo":"gchq/CyberChef","slug":"invalid-file-type-56a5bd","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ImageHueSaturationLightness.mjs","lineNumber":66,"sourceCode":"                name: \"Lightness\",\n                type: \"number\",\n                value: 0,\n                min: -100,\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 [hue, saturation, lightness] = 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 (hue !== 0) {\n                if (isWorkerEnvironment())\n                    self.sendStatusMessage(\"Changing image hue...\");\n                image.color([\n                    {\n                        apply: \"hue\",\n                        params: [hue],\n                    },\n                ]);","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ImageHueSaturationLightness.mjs#L48-L84","documentation":"Thrown at the top of ImageHueSaturationLightness.run() because isImage(input) returned falsy before Jimp ever sees the data. CyberChef's isImage (src/core/lib/FileType.mjs:240) matches image magic bytes (PNG/JPEG/GIF/BMP/etc.); any non-image or unrecognized signature fails. It is an OperationError, so the recipe surfaces it as the step's output instead of crashing the chain.","triggerScenarios":"run(input, args) is called with an ArrayBuffer whose leading bytes are not a known image signature: pasted text, a hex/PE/zip blob, or an image whose header was stripped. Also when the previous recipe step's outputType is not an ArrayBuffer image (e.g. a decoder feeding raw bytes) and the op input-type selector disagrees.","commonSituations":"Pasting plain text or hex into the op, chaining after a decode/extract step whose output is not an image, or feeding a modern format (AVIF/HEIC/WebP variants) absent from the signature DB. Re-selecting input format after the buffer changed also mismatches.","solutions":["Run the 'Detect File Type' op on the input to confirm it is actually an image.","Make sure the upstream step outputs an image ArrayBuffer (e.g. render/decode to PNG first).","Set the op's input type to match the real data (File vs Hex vs Base64).","For exotic formats, convert the source to PNG/JPEG before this operation."],"exampleFix":"// before\nconst buf = new TextEncoder().encode('hello').buffer;\nhslOp.run(buf, [0, 0, 0]); // throws 'Invalid file type.'\n// after\nimport { isImage } from \"src/core/lib/FileType.mjs\";\nif (isImage(pngBuffer) === false) throw new Error('feed a real image');\nhslOp.run(pngBuffer, [0, 0, 0]);","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 HSL 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'; // mime string, not false\n}","tryCatchPattern":null,"preventionTips":["Always probe with isImage() before invoking an image operation.","Confirm upstream recipe steps output an image ArrayBuffer.","Use Detect File Type to verify unknown input before chaining.","Keep the op input-format selector in sync with the real data."],"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"}