{"record":{"id":"861bcfb443650256","repo":"gchq/CyberChef","slug":"invalid-file-type-861bcf","errorCode":null,"errorMessage":"Invalid file type.","messagePattern":"Invalid file type\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/CropImage.mjs","lineNumber":107,"sourceCode":"    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    async run(input, args) {\n        const [\n            xPos,\n            yPos,\n            width,\n            height,\n            autocrop,\n            autoTolerance,\n            autoFrames,\n            autoSymmetric,\n            autoBorder,\n        ] = args;\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(\"Cropping image...\");\n            if (autocrop) {\n                image.autocrop({\n                    tolerance: autoTolerance / 100,\n                    cropOnlyFrames: autoFrames,\n                    cropSymmetric: autoSymmetric,\n                    leaveBorder: autoBorder,\n                });","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/CropImage.mjs#L89-L125","documentation":"Crop Image performs a manual crop (x, y, width, height) or an autocrop. 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; 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.","Decode hex/base64 input with From Hex / From Base64 first.","Confirm with Detect File Type before cropping."],"exampleFix":"// before: passing hex text directly\ninput = \"89504e47...\";\n// after\nrecipe: [From Hex, Crop 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"}