{"record":{"id":"74de1c6ae0668fd9","repo":"gchq/CyberChef","slug":"invalid-file-type-74de1c","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"warning","filePath":"src/core/operations/FlipImage.mjs","lineNumber":98,"sourceCode":"            }\n            return imageBuffer.buffer;\n        } catch (err) {\n            throw new OperationError(`Error flipping image. (${err})`);\n        }\n    }\n\n    /**\n     * Displays the flipped image using HTML for web apps\n     * @param {ArrayBuffer} data\n     * @returns {html}\n     */\n    present(data) {\n        if (!data.byteLength) return \"\";\n        const dataArray = new Uint8Array(data);\n\n        const type = isImage(dataArray);\n        if (!type) {\n            throw new OperationError(\"Invalid file type.\");\n        }\n\n        return `<img src=\"data:${type};base64,${toBase64(dataArray)}\">`;\n    }\n}\n\nexport default FlipImage;\n","sourceCodeStart":80,"sourceCodeEnd":106,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/FlipImage.mjs#L80-L106","documentation":"Thrown in the present() method when isImage() returns falsy on the operation's output buffer. present() renders the flipped image as an HTML <img> tag and must confirm the output is still a recognizable image type. In normal flow this is defensive: run() just produced image bytes, so this fires mainly when the output buffer is empty or somehow not image-typed.","triggerScenarios":"The flipped output buffer has no detectable image magic bytes; data.byteLength is non-zero but the bytes are not a valid image header (e.g. an upstream op returned garbage); an empty/zero-length buffer that bypassed the byteLength guard by being non-zero but corrupt.","commonSituations":"Chaining ops where an intermediate step corrupts the buffer; a custom present path invoked on stale/modified data; edge cases where Jimp getBuffer returned incomplete bytes.","solutions":["Inspect the output ArrayBuffer from run() to confirm it has valid image magic bytes.","Ensure no downstream op mutates the buffer before present() is called.","If reproducing in Node (no present path), note present() only runs in the browser UI."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { isImage } from \"../lib/FileType.mjs\";\n// present() only runs in the browser; guard the buffer before rendering\nconst arr = new Uint8Array(data);\nif (!arr.byteLength || !isImage(arr)) return ''; // skip rendering instead of throwing","typeGuard":"function isPresentableImage(buf) {\n  const arr = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;\n  return arr.byteLength > 0 && !!isImage(arr);\n}","tryCatchPattern":null,"preventionTips":["Remember present() executes only in the browser UI, not the Node API.","Ensure no downstream op corrupts the output buffer before presentation.","Treat a present() failure as a symptom of upstream corruption."],"tags":["image","presentation","file-type","ui","defensive-check"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}