{"record":{"id":"e8f973a36c7794b7","repo":"gchq/CyberChef","slug":"unsupported-file-type-supported-jpg-png-pbm-bmp","errorCode":null,"errorMessage":"Unsupported file type (supported: jpg,png,pbm,bmp) or no file provided","messagePattern":"Unsupported file type \\(supported: jpg,png,pbm,bmp\\) or no file provided","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/OpticalCharacterRecognition.mjs","lineNumber":63,"sourceCode":"                value: OEM_MODES,\n                defaultIndex: 1\n            }\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    async run(input, args) {\n        const [showConfidence, oemChoice] = args;\n\n        if (!isWorkerEnvironment()) throw new OperationError(\"This operation only works in a browser\");\n\n        const type = isImage(input);\n        if (!type) {\n            throw new OperationError(\"Unsupported file type (supported: jpg,png,pbm,bmp) or no file provided\");\n        }\n\n        const assetDir = `${self.docURL}/assets/`;\n        const oem = OEM_MODES.indexOf(oemChoice);\n\n        try {\n            self.sendStatusMessage(\"Spinning up Tesseract worker...\");\n            const image = `data:${type};base64,${toBase64(input)}`;\n            const worker = await createWorker(\"eng\", oem, {\n                workerPath: `${assetDir}tesseract/worker.min.js`,\n                langPath: `${assetDir}tesseract/lang-data`,\n                corePath: `${assetDir}tesseract/tesseract-core.wasm.js`,\n                logger: progress => {\n                    if (isWorkerEnvironment()) {\n                        self.sendStatusMessage(`Status: ${progress.status}${progress.status === \"recognizing text\" ? ` - ${(parseFloat(progress.progress)*100).toFixed(2)}%`: \"\" }`);\n                    }\n                }\n            });","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/OpticalCharacterRecognition.mjs#L45-L81","documentation":"Thrown by OpticalCharacterRecognition.run when isImage(input) returns false — the input is not a recognised image (jpg, png, pbm, bmp). Tesseract can only process raster images, so non-image data or unsupported formats (e.g. tiff, webp) are rejected before the worker is created.","triggerScenarios":"run(input, args) with an ArrayBuffer whose magic bytes are not a supported image type. Feeding a PDF, TIFF, WebP, text, or empty buffer, or a file with a spoofed extension, trips this.","commonSituations":"Dropped a PDF or TIFF (Tesseract supports them but CyberChef's sniffer gate does not); uploaded a screenshot saved as WebP; upstream operation produced a non-ArrayBuffer; empty buffer from a failed load; file renamed to .png but actually a document.","solutions":["Convert the source to PNG, JPG, PBM, or BMP before feeding it in.","For PDFs, rasterise to PNG first (e.g. via a render operation or external tool).","Ensure the upstream op outputs an ArrayBuffer containing the raw image bytes.","Verify the buffer is non-empty and begins with the correct magic bytes."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"import { isImage } from \"core/lib/FileType.mjs\";\nif (!isImage(input)) {\n  // convert to PNG/JPG/PBM/BMP before running OCR\n}","typeGuard":"const isOCRImage = (buf) => Boolean(isImage(buf));","tryCatchPattern":"try { await chef.bake(\"Optical Character Recognition\", args, input); }\ncatch (e) { if (e.message.startsWith(\"Unsupported file type\")) convertToPNG(); else throw e; }","preventionTips":["Pre-convert PDFs/TIFFs/WebPs to PNG.","Verify the buffer is non-empty and starts with image magic bytes.","Ensure upstream ops emit an ArrayBuffer of raw image bytes."],"tags":["ocr","image","file-type","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}