gchq/CyberChef · error · OperationError

Blocksize must be a positive integer.

Error message

Blocksize must be a positive integer.

What it means

Thrown by XORChecksum.run when validating args[0] ('Blocksize'). The checksum XORs fixed-size blocks, so the size must be a positive integer; Number.isInteger(x) && x > 0 guards both fractional values and non-positive ones. The default is 4 (declared in the constructor), so a valid UI invocation never hits this — it only fires when a number argument is supplied out of range.

Source

Thrown at src/core/operations/XORChecksum.mjs:48

            {
                name: "Blocksize",
                type: "number",
                value: 4,
            },
        ];
    }

    /**
     * @param {ArrayBuffer} input
     * @param {Object[]} args
     * @returns {string}
     */
    run(input, args) {
        const blocksize = args[0];


        if (!Number.isInteger(blocksize) || blocksize <= 0) {
            throw new OperationError("Blocksize must be a positive integer.");
        }

        input = new Uint8Array(input);

        const res = Array(blocksize);
        res.fill(0);

        for (const chunk of Utils.chunked(input, blocksize)) {
            for (let i = 0; i < blocksize; i++) {
                res[i] ^= chunk[i];
            }
        }

        return toHex(res, "");
    }
}

export default XORChecksum;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Pass a positive integer (>=1) for the Blocksize argument, e.g. 1, 2, 4, 8.
  2. Ensure the value is a real number, not a JSON string: '4' fails; 4 passes.
  3. If computing blocksize dynamically, clamp with Math.max(1, Math.floor(n)) and confirm it is an integer before building the recipe.

Example fix

// before
chef.bake(input, [{op:"XOR Checksum", args:["4"]}]); // string -> not an integer
chef.bake(input, [{op:"XOR Checksum", args:[0]}]);   // not positive
// after
chef.bake(input, [{op:"XOR Checksum", args:[4]}]);
Defensive patterns

Strategy: validation

Validate before calling

function buildXorRecipe(blocksize) {
  if (!Number.isInteger(blocksize) || blocksize <= 0) throw new Error("blocksize must be a positive integer");
  return [{op:"XOR Checksum", args:[blocksize]}];
}

Type guard

const isPositiveInt = (n) => Number.isInteger(n) && n > 0;

Try / catch

try { result = chef.bake(input, recipe); } catch (e) { if (/Blocksize must be a positive integer/.test(e.message)) { /* coerce: recipe[0].args[0] = Math.max(1, Math.floor(x)) */ } else throw e; }

Prevention

When it happens

Trigger: Blocksize is supplied as 0, a negative number, NaN/Infinity, a fractional value (e.g. 2.5), or is missing/corrupted in a programmatic opList. Strings are not integers, so passing '4' as a JSON string also fails Number.isInteger.

Common situations: Hand-built recipe JSON where the number was serialised as a string; a UI/config preset copied with blocksize 0; off-by-one when deriving blocksize from input length.

Related errors


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