{"record":{"id":"5c1e93dc479b2198","repo":"gchq/CyberChef","slug":"error-covering-image-err","errorCode":null,"errorMessage":"Error covering image. (${err})","messagePattern":"Error covering image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/CoverImage.mjs","lineNumber":130,"sourceCode":"        }\n        try {\n            if (isWorkerEnvironment())\n                self.sendStatusMessage(\"Covering image...\");\n            image.cover({\n                w: width,\n                h: height,\n                align: alignMap[hAlign] | alignMap[vAlign],\n                mode: resizeMap[alg],\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 covering image. (${err})`);\n        }\n    }\n\n    /**\n     * Displays the covered image using HTML for web apps\n     * @param {ArrayBuffer} data\n     * @returns {html}\n     */\n    present(data) {\n        if (!data.byteLength) return \"\";\n        const dataArray = new Uint8Array(data);\n\n        const type = isImage(dataArray);\n        if (!type) {\n            throw new OperationError(\"Invalid file type.\");\n        }\n\n        return `<img src=\"data:${type};base64,${toBase64(dataArray)}\">`;","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/CoverImage.mjs#L112-L148","documentation":"After a successful load, Cover Image runs image.cover() and then image.getBuffer() to export. Any failure in the cover/resize or the buffer export is caught and re-thrown as 'Error covering image.' The dominant preventable cause is invalid target dimensions.","triggerScenarios":"Width or height of 0 or negative; extremely large dimensions exhausting memory; an unsupported resize algorithm mapping to undefined; getBuffer encode failure.","commonSituations":"Recipe/script passing width=0 or height=0; oversized targets; algorithm string typo.","solutions":["Ensure Width and Height are integers >= 1 and memory-reasonable.","Use a supported resizing algorithm option.","Downscale very large images in stages."],"exampleFix":"// before\nconst args = [0, 0, \"Center\", \"Middle\", \"Bilinear\"];\n// after\nconst args = [100, 100, \"Center\", \"Middle\", \"Bilinear\"];","handlingStrategy":"validation","validationCode":"function validDims(width, height) {\n  return Number.isInteger(width) && Number.isInteger(height) && width >= 1 && height >= 1;\n}\nif (!validDims(width, height)) {\n  throw new Error(`Invalid cover dimensions: width=${width}, height=${height}`);\n}\nconst ALGS = [\"Nearest Neighbour\", \"Bilinear\", \"Bicubic\", \"Hermite\", \"Bezier\"];\nif (!ALGS.includes(alg)) {\n  throw new Error(`Unsupported resize algorithm: ${alg}`);\n}","typeGuard":"function isCoverArgs(width, height, alg) {\n  return Number.isInteger(width) && width >= 1 &&\n    Number.isInteger(height) && height >= 1 &&\n    [\"Nearest Neighbour\", \"Bilinear\", \"Bicubic\", \"Hermite\", \"Bezier\"].includes(alg);\n}","tryCatchPattern":"try {\n  result = await coverImage.run(input, args);\n} catch (err) {\n  if (/Error covering image/.test(err.message)) {\n    // Most often width/height <= 0 or unsupported algorithm. Re-check args.\n  }\n  throw err;\n}","preventionTips":["Keep Width and Height as integers >= 1 and memory-reasonable.","Use only the supported resizing-algorithm option strings.","Cap target dimensions for very large sources."],"tags":["cyberchef","image","jimp","resize","operation-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}