{"record":{"id":"9c09f4dd30b6fdd9","repo":"gchq/CyberChef","slug":"invalid-custom-crc-arguments","errorCode":null,"errorMessage":"Invalid custom CRC arguments","messagePattern":"Invalid custom CRC arguments","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/CRCChecksum.mjs","lineNumber":916,"sourceCode":"     * @param {ArrayBuffer} input\n     * @param {Object} polyObject\n     * @param {Object} initObject\n     * @param {Object} reflectInObject\n     * @param {Object} reflectOutObject\n     * @param {Object} xorOutObject\n     */\n    custom(widthObject, input, polyObject, initObject, reflectInObject, reflectOutObject, xorOutObject) {\n        try {\n            const width = BigInt(widthObject.string);\n            const poly = BigInt(\"0x\" + polyObject.string);\n            const init = BigInt(\"0x\" + initObject.string);\n            const reflectIn = reflectInObject === \"True\";\n            const reflectOut = reflectOutObject === \"True\";\n            const xorOut = BigInt(\"0x\" + xorOutObject.string);\n\n            return this.crc(width, input, poly, init, reflectIn, reflectOut, xorOut);\n        } catch (error) {\n            throw new OperationError(\"Invalid custom CRC arguments\");\n        }\n    }\n\n    /**\n     * Calculation of all known CRCs. Names and constants extracted from https://reveng.sourceforge.io/crc-catalogue/all.htm\n     *\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const algorithm = args[0];\n        input = new Uint8Array(input);\n\n        switch (algorithm) {\n            case \"Custom\":                   return this.custom(args[1], input, args[2], args[3], args[4], args[5], args[6]);\n            case \"CRC-3/GSM\":                return this.crc(3n, input, 0x3n, 0x0n, false, false, 0x7n);\n            case \"CRC-3/ROHC\":               return this.crc(3n, input, 0x3n, 0x7n, true,  true,  0x0n);","sourceCodeStart":898,"sourceCodeEnd":934,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/CRCChecksum.mjs#L898-L934","documentation":"The custom CRC builder parses width, poly, init, and xorOut via BigInt (with poly/init/xorOut prefixed by '0x'). Any malformed hex/decimal string, a width outside the supported range, or a downstream crc() computation failure is caught and rethrown as a generic 'Invalid custom CRC arguments'.","triggerScenarios":"Calling CRCChecksum.custom with a widthObject.string that is not a valid integer, or polyObject/initObject/xorOutObject.string that is not valid hexadecimal, or values that make the crc() computation throw.","commonSituations":"Typing a poly with a '0x' prefix already included (double prefix), spaces in the hex string, negative width, a width > 64 unsupported by the implementation, or empty fields.","solutions":["Provide width as a plain decimal integer string (e.g. '32').","Provide poly/init/xorOut as raw hex digits without a leading '0x' (the code adds it).","Keep width within the range the crc() implementation supports.","Strip whitespace from all argument strings."],"exampleFix":"// before\nwidth='0x20', poly='0x04C11DB7'\n// after\nwidth='32', poly='04C11DB7'","handlingStrategy":"validation","validationCode":"function validateCustomCrc(widthStr, hexStrs) {\n  if (!/^\\d+$/.test(widthStr)) throw new Error('width must be decimal');\n  for (const h of hexStrs) if (!/^[0-9a-fA-F]+$/.test(h)) throw new Error('hex field invalid: ' + h);\n}","typeGuard":"function isHexNoPrefix(s) { return /^[0-9a-fA-F]+$/.test(s); }\nfunction isDecimal(s) { return /^\\d+$/.test(s); }","tryCatchPattern":"try { crcCustom(width, input, poly, init, reflectIn, reflectOut, xorOut); }\ncatch (e) { if (/Invalid custom CRC arguments/.test(e.message)) { /* re-prompt user for params */ } else throw e; }","preventionTips":["Provide width as decimal, poly/init/xorOut as hex without '0x'.","Strip whitespace from all fields.","Keep width within the implementation's supported range."],"tags":["crc","validation","bigint","checksum"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}