{"record":{"id":"5d3db393da22961b","repo":"gchq/CyberChef","slug":"please-enter-a-valid-image-file-5d3db3","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/ViewBitPlane.mjs","lineNumber":53,"sourceCode":"                type: \"option\",\n                value: COLOUR_OPTIONS,\n            },\n            {\n                name: \"Bit\",\n                type: \"number\",\n                value: 0,\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 [colour, bit] = args;\n        let parsedImage;\n        try {\n            parsedImage = await Jimp.read(input);\n        } catch (err) {\n            throw new OperationError(`Error loading image. (${err})`);\n        }\n\n        const width = parsedImage.bitmap.width,\n            height = parsedImage.bitmap.height,\n            colourIndex = COLOUR_OPTIONS.indexOf(colour),\n            bitIndex = 7 - bit;\n\n        if (bit < 0 || bit > 7) {\n            throw new OperationError(\n                \"Error: Bit argument must be between 0 and 7\",\n            );","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ViewBitPlane.mjs#L35-L71","documentation":"Thrown by 'View Bit Plane' when isImage(input) returns false. The operation expects an ArrayBuffer containing a recognised image; if the magic bytes / content type are not a supported image format it aborts before attempting Jimp parsing.","triggerScenarios":"Passing non-image bytes (text, a zip, raw bytes), an unsupported image format, or a truncated image header. Input must arrive as an ArrayBuffer whose magic bytes pass CyberChef's isImage check.","commonSituations":"Forgetting to switch the input type, piping a string/text operation output directly into View Bit Plane, or supplying a file format Jimp/isImage does not support (e.g. certain TIFF/HEIC variants).","solutions":["Provide a supported image file (PNG/JPEG/BMP/GIF etc.) as an ArrayBuffer.","Ensure the upstream operation outputs bytes (e.g. 'From Base64' or a file input) rather than text.","If the source is a different format, convert it to PNG first."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if (!isImage(input)) throw new Error(\"Input is not a recognised image format\");","typeGuard":"function isImage(buf) { return buf instanceof ArrayBuffer && /\\x89PNG|\\xff\\xd8\\xff|GIF8|BM/.test(String.fromCharCode(...new Uint8Array(buf.slice(0,4)))); }","tryCatchPattern":null,"preventionTips":["Feed image bytes via file input or From Base64, not raw text.","Confirm the format is supported (PNG/JPEG/BMP/GIF)."],"tags":["image","validation","input-type","jimp"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}