{"record":{"id":"ace92cc9f129cfe8","repo":"gchq/CyberChef","slug":"width-must-be-no-more-than-max-width","errorCode":null,"errorMessage":"Width must be no more than ${MAX_WIDTH}","messagePattern":"Width must be no more than (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ToHexdump.mjs","lineNumber":70,"sourceCode":"            }\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const data = new Uint8Array(input);\n        const [length, upperCase, includeFinalLength, unixFormat] = args;\n        const padding = 2;\n\n        if (length < 1 || Math.round(length) !== length)\n            throw new OperationError(\"Width must be a positive integer\");\n\n        if (length > MAX_WIDTH)\n            throw new OperationError(`Width must be no more than ${MAX_WIDTH}`);\n\n        const lines = [];\n        for (let i = 0; i < data.length; i += length) {\n            let lineNo = Utils.hex(i, 8);\n\n            const buff = data.slice(i, i+length);\n            const hex = [];\n            buff.forEach(b => hex.push(Utils.hex(b, padding)));\n            let hexStr = hex.join(\" \").padEnd(length*(padding+1), \" \");\n\n            const ascii = Utils.printable(Utils.byteArrayToChars(buff), false, unixFormat);\n            const asciiStr = ascii.padEnd(buff.length, \" \");\n\n            if (upperCase) {\n                hexStr = hexStr.toUpperCase();\n                lineNo = lineNo.toUpperCase();\n            }\n","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ToHexdump.mjs#L52-L88","documentation":"To Hexdump caps the line width at MAX_WIDTH to keep the rendered output within practical bounds. The guard throws when the length argument exceeds that constant, after the positive-integer check has already passed.","triggerScenarios":"Setting the length argument to a value greater than MAX_WIDTH (defined at the top of the module).","commonSituations":"Requesting an extremely wide row for compactness; misreading the cap; copying a config from a fork with a different MAX_WIDTH.","solutions":["Reduce the length argument to MAX_WIDTH or below (typically use 16 or 32).","Check the module's MAX_WIDTH constant for the exact bound.","Split large data across multiple operations if wider rows are truly needed."],"exampleFix":"// before: args[0] (length) = 999 (> MAX_WIDTH) -> throws\n// after:  args[0] (length) = 16                 -> within cap, passes","handlingStrategy":"validation","validationCode":"if (length > MAX_WIDTH) {\n  throw new Error(`Hexdump width must be <= ${MAX_WIDTH}`);\n}","typeGuard":"const withinMaxWidth = w => Number.isInteger(w) && w >= 1 && w <= MAX_WIDTH;","tryCatchPattern":"try { toHexdump(input, [length, ...rest]); }\ncatch (e) { if (/no more than/.test(e.message)) { length = MAX_WIDTH; } else throw e; }","preventionTips":["Cap the width field at MAX_WIDTH in the UI.","Use conventional widths (16/32) for readability.","Read the module constant to know the exact bound."],"tags":["hexdump","validation","limit","argument"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}