{"record":{"id":"e47acec2b5681e97","repo":"gchq/CyberChef","slug":"error-loading-image-err-e47ace","errorCode":null,"errorMessage":"Error loading image. (${err})","messagePattern":"Error loading image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/InvertImage.mjs","lineNumber":48,"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 input file format.\");\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(\"Inverting image...\");\n            image.invert();\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 inverting image. (${err})`);\n        }\n    }\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/InvertImage.mjs#L30-L66","documentation":"Wraps any failure of Jimp.read(input) inside InvertImage.run(). The magic bytes passed isImage but Jimp could not decode the body. The original error is interpolated. OperationError surfaced as step output.","triggerScenarios":"isImage accepted the signature but Jimp rejects the payload: truncated file, corrupt body, or a codec Jimp lacks. An ArrayBuffer shorter than the header implies is common.","commonSituations":"Truncated copy-paste, browser-renderable but Jimp-undecodable images, jimp version skew, valid signature around unrelated bytes.","solutions":["Read ${err} for Jimp's specific reason.","Re-save the source as PNG or JPEG and retry.","Confirm buffer length matches declared dimensions.","Verify jimp supports the codec."],"exampleFix":"// before\ninvertOp.run(truncatedPng, []); // -> Error loading image.\n// after\nconst buf = await reencodeToPng(truncatedPng);\ninvertOp.run(buf, []);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await invertOp.run(buf, []);\n} catch (e) {\n  if (e instanceof OperationError && /Error loading image/.test(e.message)) {\n    reportCorruptImage(e.message);\n  } else throw e;\n}","preventionTips":["Re-encode untrusted images to PNG first.","Validate buffer length against the header.","Pin a known-good jimp version.","Surface Jimp's interpolated reason."],"tags":["image","jimp","decoding","cyberchef","error-handling"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}