gchq/CyberChef · error · OperationError

Invalid custom CRC arguments

Error message

Invalid custom CRC arguments

What it means

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'.

Source

Thrown at src/core/operations/CRCChecksum.mjs:916

     * @param {ArrayBuffer} input
     * @param {Object} polyObject
     * @param {Object} initObject
     * @param {Object} reflectInObject
     * @param {Object} reflectOutObject
     * @param {Object} xorOutObject
     */
    custom(widthObject, input, polyObject, initObject, reflectInObject, reflectOutObject, xorOutObject) {
        try {
            const width = BigInt(widthObject.string);
            const poly = BigInt("0x" + polyObject.string);
            const init = BigInt("0x" + initObject.string);
            const reflectIn = reflectInObject === "True";
            const reflectOut = reflectOutObject === "True";
            const xorOut = BigInt("0x" + xorOutObject.string);

            return this.crc(width, input, poly, init, reflectIn, reflectOut, xorOut);
        } catch (error) {
            throw new OperationError("Invalid custom CRC arguments");
        }
    }

    /**
     * Calculation of all known CRCs. Names and constants extracted from https://reveng.sourceforge.io/crc-catalogue/all.htm
     *
     * @param {ArrayBuffer} input
     * @param {Object[]} args
     * @returns {string}
     */
    run(input, args) {
        const algorithm = args[0];
        input = new Uint8Array(input);

        switch (algorithm) {
            case "Custom":                   return this.custom(args[1], input, args[2], args[3], args[4], args[5], args[6]);
            case "CRC-3/GSM":                return this.crc(3n, input, 0x3n, 0x0n, false, false, 0x7n);
            case "CRC-3/ROHC":               return this.crc(3n, input, 0x3n, 0x7n, true,  true,  0x0n);

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide width as a plain decimal integer string (e.g. '32').
  2. Provide poly/init/xorOut as raw hex digits without a leading '0x' (the code adds it).
  3. Keep width within the range the crc() implementation supports.
  4. Strip whitespace from all argument strings.

Example fix

// before
width='0x20', poly='0x04C11DB7'
// after
width='32', poly='04C11DB7'
Defensive patterns

Strategy: validation

Validate before calling

function validateCustomCrc(widthStr, hexStrs) {
  if (!/^\d+$/.test(widthStr)) throw new Error('width must be decimal');
  for (const h of hexStrs) if (!/^[0-9a-fA-F]+$/.test(h)) throw new Error('hex field invalid: ' + h);
}

Type guard

function isHexNoPrefix(s) { return /^[0-9a-fA-F]+$/.test(s); }
function isDecimal(s) { return /^\d+$/.test(s); }

Try / catch

try { crcCustom(width, input, poly, init, reflectIn, reflectOut, xorOut); }
catch (e) { if (/Invalid custom CRC arguments/.test(e.message)) { /* re-prompt user for params */ } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/9c09f4dd30b6fdd9. Report an issue: GitHub.