{"record":{"id":"10f6ef970b28c379","repo":"gchq/CyberChef","slug":"invalid-file-type-10f6ef","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ContainImage.mjs","lineNumber":109,"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        const originalMime = image.mime;\n        try {\n            if (isWorkerEnvironment())\n                self.sendStatusMessage(\"Containing image...\");\n            image.contain({\n                w: width,\n                h: height,\n                align: alignMap[hAlign] | alignMap[vAlign],\n                mode: resizeMap[alg],\n            });","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ContainImage.mjs#L91-L127","documentation":"Contain Image scales an image to a target width/height while preserving aspect ratio (letterboxing). Before any processing it validates the input ArrayBuffer via isImage(), which sniffs magic bytes against CyberChef's recognized image MIME types. If the bytes are not a supported image, `if (!isImage(input))` throws 'Invalid file type.' This is an input-shape check distinct from the later Jimp decode step.","triggerScenarios":"Feeding non-image bytes (text, PDF, ZIP, executable); a truncated file whose magic bytes are missing; an empty ArrayBuffer; an image format not in isImage's signature table; feeding a string when an ArrayBuffer of raw bytes is required.","commonSituations":"Chaining Contain Image after an operation that emits non-image output; uploading the wrong file; forgetting to decode (e.g. feeding hex text instead of using From Hex first); using a format CyberChef's type detector doesn't recognize.","solutions":["Supply a raw image ArrayBuffer in a format isImage recognizes (PNG, JPEG, BMP, GIF, etc.).","If your input is encoded (hex/base64), run From Hex / From Base64 before Contain Image.","Precede the operation with Detect File Type to confirm the bytes are detected as an image."],"exampleFix":"// before: feeding hex text directly\ninput = \"89504e470d0a...\"; // string -> isImage false\n// after: decode to raw bytes first\nrecipe: [From Hex, Contain Image]","handlingStrategy":"type-guard","validationCode":"import { isImage } from \"src/core/lib/FileType.mjs\";\nconst buf = input instanceof ArrayBuffer ? new Uint8Array(input) : input;\nif (!isImage(buf)) {\n  throw new Error(\"Input is not a recognized image; supply raw image bytes (decode hex/base64 first if needed).\");\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, not hex/base64 text — decode first with From Hex / From Base64.","Use Detect File Type upstream to confirm the bytes are an image.","Confirm the format is in isImage's recognized signature table before chaining Contain Image."],"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"}