{"record":{"id":"2ebb4198bd1dea1c","repo":"gchq/CyberChef","slug":"invalid-file-type-2ebb41","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/CoverImage.mjs","lineNumber":104,"sourceCode":"        const resizeMap = {\n            \"Nearest Neighbour\": ResizeStrategy.NEAREST_NEIGHBOR,\n            Bilinear: ResizeStrategy.BILINEAR,\n            Bicubic: ResizeStrategy.BICUBIC,\n            Hermite: ResizeStrategy.HERMITE,\n            Bezier: ResizeStrategy.BEZIER,\n        };\n\n        const alignMap = {\n            Left: HorizontalAlign.LEFT,\n            Center: HorizontalAlign.CENTER,\n            Right: HorizontalAlign.RIGHT,\n            Top: VerticalAlign.TOP,\n            Middle: VerticalAlign.MIDDLE,\n            Bottom: VerticalAlign.BOTTOM,\n        };\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 (isWorkerEnvironment())\n                self.sendStatusMessage(\"Covering image...\");\n            image.cover({\n                w: width,\n                h: height,\n                align: alignMap[hAlign] | alignMap[vAlign],\n                mode: resizeMap[alg],\n            });\n            let imageBuffer;","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/CoverImage.mjs#L86-L122","documentation":"Cover Image scales an image to fill a target width/height while preserving aspect ratio (cropping overflow). It validates the input via isImage() first; non-image bytes cause `if (!isImage(input))` to throw 'Invalid file type.' This is the magic-byte input check before Jimp decoding.","triggerScenarios":"Non-image bytes (text/PDF/ZIP/etc.); truncated file missing magic bytes; empty ArrayBuffer; a format absent from isImage's signature table; passing a string instead of raw bytes.","commonSituations":"Wrong input; chaining after a non-image-producing op; forgetting to decode hex/base64; unsupported image format.","solutions":["Supply a raw image ArrayBuffer isImage recognizes (PNG/JPEG/BMP/GIF etc.).","Decode hex/base64 input with From Hex / From Base64 first.","Confirm with Detect File Type before covering."],"exampleFix":"// before: passing base64 text directly\ninput = \"iVBORw0KGgo...\";\n// after\nrecipe: [From Base64, Cover Image]","handlingStrategy":"type-guard","validationCode":"import { isImage } from \"src/core/lib/FileType.mjs\";\nconst bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : input;\nif (!isImage(bytes)) {\n  throw new Error(\"Input is not a recognized image; supply raw image bytes.\");\n}","typeGuard":"import { isImage } from \"src/core/lib/FileType.mjs\";\nfunction isImageInput(buf) {\n  const bytes = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;\n  return isImage(bytes) !== false;\n}","tryCatchPattern":null,"preventionTips":["Feed raw image bytes; decode hex/base64 first.","Use Detect File Type to confirm the input is an image.","Confirm the format is in isImage's recognized signature table."],"tags":["cyberchef","image","jimp","file-type","input-validation","operation-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}