{"record":{"id":"1e02e533a4639cb1","repo":"gchq/CyberChef","slug":"error-opening-image-file-err-1e02e5","errorCode":null,"errorMessage":"Error opening image file. (${err})","messagePattern":"Error opening image file\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/NormaliseImage.mjs","lineNumber":47,"sourceCode":"        this.presentType = \"html\";\n        this.args = [];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    async run(input, 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 opening image file. (${err})`);\n        }\n\n        try {\n            image.normalize();\n\n            let imageBuffer;\n            if (image.mime === \"image/gif\") {\n                imageBuffer = await image.getBuffer(JimpMime.png);\n            } else {\n                imageBuffer = await image.getBuffer(image.mime);\n            }\n            return imageBuffer.buffer;\n        } catch (err) {\n            throw new OperationError(`Error normalising image. (${err})`);\n        }\n    }\n\n    /**","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/NormaliseImage.mjs#L29-L65","documentation":"Thrown by NormaliseImage.run when Jimp.read(input) rejects. The magic-byte check (isImage) passed, but Jimp could not decode the buffer — typically because the file is truncated, has a valid header but corrupt body, or uses a sub-format Jimp does not support. The original error is interpolated into the message.","triggerScenarios":"run(input, args) where isImage returns a MIME type but Jimp.read() throws asynchronously. Examples: a JPEG with a correct SOI marker but truncated scan data; a PNG missing IDAT; a GIF89a header with no image data; a WebP/HEIC that fooled the sniffer.","commonSituations":"Corrupt download; image truncated by a size limit; CMYK or exotic colour-space JPEG; progressive JPEG with missing segments; file that had its header patched to look like an image.","solutions":["Re-obtain the source image from a known-good copy.","Open the file in an image editor and re-export to repair structure.","Inspect the interpolated err string for the specific Jimp failure.","If the format is unusual (WebP/HEIC), convert to PNG/JPG first with another tool."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await chef.bake(\"Normalise Image\", [], input);\n} catch (e) {\n  if (e.message.startsWith(\"Error opening image file.\")) {\n    // re-export the source image, then retry\n  } else throw e;\n}","preventionTips":["Source images from trusted, complete files.","Re-export exotic colour spaces to sRGB PNG/JPG first.","Inspect the interpolated err for the Jimp-specific cause."],"tags":["image","jimp","decode-error","corrupt-file"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}