{"record":{"id":"e5dafd58957bceaf","repo":"gchq/CyberChef","slug":"please-enter-a-valid-image-file-e5dafd","errorCode":null,"errorMessage":"Please enter a valid image file.","messagePattern":"Please enter a valid image file\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/RandomizeColourPalette.mjs","lineNumber":49,"sourceCode":"        this.outputType = \"ArrayBuffer\";\n        this.presentType = \"html\";\n        this.args = [\n            {\n                name: \"Seed\",\n                type: \"string\",\n                value: \"\",\n            },\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {ArrayBuffer}\n     */\n    async run(input, args) {\n        if (!isImage(input))\n            throw new OperationError(\"Please enter a valid image file.\");\n\n        const seed = args[0] || Math.random().toString().substr(2),\n            parsedImage = await Jimp.read(input),\n            width = parsedImage.bitmap.width,\n            height = parsedImage.bitmap.height;\n\n        let rgbString, rgbHash, rgbHex;\n\n        parsedImage.scan(0, 0, width, height, function (x, y, idx) {\n            rgbString = this.bitmap.data.slice(idx, idx + 3).join(\".\");\n            rgbHash = runHash(\"md5\", Utils.strToArrayBuffer(seed + rgbString));\n            rgbHex = rgbHash.substr(0, 6) + \"ff\";\n            parsedImage.setPixelColor(parseInt(rgbHex, 16), x, y);\n        });\n\n        const imageBuffer = await parsedImage.getBuffer(parsedImage.mime);\n\n        return new Uint8Array(imageBuffer).buffer;","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/RandomizeColourPalette.mjs#L31-L67","documentation":"Thrown by RandomizeColourPalette when the input is not recognized by CyberChef's isImage() check as a supported image format (PNG/JPEG/GIF/BMP/etc.). The operation needs a decodable image to scan pixels and remap colours.","triggerScenarios":"Feeding non-image bytes (text, archives, audio); a corrupted or truncated image file; an unsupported/obscure image format.","commonSituations":"Piping the wrong operation output into RandomizeColourPalette; copying a truncated image; using a format (e.g. HEIC, WebP variant) the isImage detector does not recognize.","solutions":["Confirm the input is a supported raster image (PNG/JPEG/GIF/BMP).","Re-export/convert the source image to PNG or JPEG first.","Verify the bytes were not truncated or Base64-mangled before reaching the operation.","Check that an upstream 'From Base64' / 'From Hex' step decoded correctly."],"exampleFix":"// before\n//   input: raw text or partial PNG bytes\n// after\n//   input: a complete PNG file (signature 89 50 4E 47 ...)","handlingStrategy":"type-guard","validationCode":"if (!isImage(input)) throw new Error('Input is not a supported image');","typeGuard":"const isSupportedImage = buf => Boolean(isImage(buf));","tryCatchPattern":"try { await randomizePalette(input); } catch (e) { if (/valid image/.test(e.message)) convertToPng(input); else throw e; }","preventionTips":["Pre-convert to PNG/JPEG.","Ensure upstream decoding (From Base64) ran."],"tags":["image","validation","jimp"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}