{"record":{"id":"c6a43e10a0141d79","repo":"gchq/CyberChef","slug":"invalid-file-format","errorCode":null,"errorMessage":"Invalid file format.","messagePattern":"Invalid file format\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ConvertImageFormat.mjs","lineNumber":85,"sourceCode":"            JPEG: JimpMime.jpeg,\n            PNG: JimpMime.png,\n            BMP: JimpMime.bmp,\n            TIFF: JimpMime.tiff,\n        };\n\n        const pngFilterMap = {\n            Auto: PNGFilterType.AUTO,\n            None: PNGFilterType.NONE,\n            Sub: PNGFilterType.SUB,\n            Up: PNGFilterType.UP,\n            Average: PNGFilterType.AVERAGE,\n            Paeth: PNGFilterType.PATH,\n        };\n\n        const mime = formatMap[format];\n\n        if (!isImage(input)) {\n            throw new OperationError(\"Invalid file format.\");\n        }\n        let image;\n        try {\n            image = await Jimp.read(input);\n        } catch (err) {\n            throw new OperationError(`Error opening image file. (${err})`);\n        }\n        try {\n            let buffer;\n            switch (mime) {\n                case JimpMime.jpeg:\n                    buffer = await image.getBuffer(mime, {\n                        quality: jpegQuality,\n                    });\n                    break;\n                case JimpMime.png:\n                    buffer = await image.getBuffer(mime, {\n                        filterType: pngFilterMap[pngFilterType],","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ConvertImageFormat.mjs#L67-L103","documentation":"Convert Image Format transcodes an image to a chosen target format (PNG/JPEG/BMP/etc.). It first validates the input is an image via isImage(); if the magic bytes are not a recognized image type it throws 'Invalid file format.' (note the wording differs from the other ops' 'Invalid file type').","triggerScenarios":"Feeding non-image bytes; truncated file missing magic bytes; empty ArrayBuffer; a format absent from isImage's signature table; passing a string instead of raw byte ArrayBuffer.","commonSituations":"Wrong input file; chaining after an op that outputs non-image data; forgetting to decode hex/base64 first; using a format the type detector doesn't recognize.","solutions":["Supply a raw image ArrayBuffer in a format isImage recognizes.","If input is hex/base64 encoded, run From Hex / From Base64 first.","Use Detect File Type to confirm the bytes are an image before converting."],"exampleFix":"// before: feeding raw text\ninput = \"some text\";\n// after: feed decoded image bytes\nrecipe: [From Base64, Convert Image Format]","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":["Decode hex/base64 input to raw bytes before converting.","Confirm with Detect File Type that the input is an image.","Ensure 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"}