gchq/CyberChef · error · OperationError

'Starting at' must be a positive or zero integer.

Error message

'Starting at' must be a positive or zero integer.

What it means

Thrown in DropNthBytes.run when the second argument start ('Starting at') fails parseInt(start,10) !== start || start < 0. The integer check rejects NaN and non-integers; start < 0 rejects negatives. Together they require a non-negative integer. Default is 0, so this fires only for an out-of-range value.

Source

Thrown at src/core/operations/DropNthBytes.mjs:60

            }
        ];
    }

    /**
     * @param {byteArray} input
     * @param {Object[]} args
     * @returns {byteArray}
     */
    run(input, args) {
        const n = args[0];
        const start = args[1];
        const eachLine = args[2];

        if (parseInt(n, 10) !== n || n <= 0) {
            throw new OperationError("'Drop every' must be a positive integer.");
        }
        if (parseInt(start, 10) !== start || start < 0) {
            throw new OperationError("'Starting at' must be a positive or zero integer.");
        }

        let offset = 0;
        const output = [];
        for (let i = 0; i < input.length; i++) {
            if (eachLine && input[i] === 0x0a) {
                output.push(0x0a);
                offset = i + 1;
            } else if (i - offset < start || (i - (start + offset)) % n !== 0) {
                output.push(input[i]);
            }
        }

        return output;
    }

}

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set 'Starting at' to 0 or a positive whole number.
  2. Programmatically, coerce with Math.max(0, Math.floor(start)).
  3. Move the constraint into the Ingredient args metadata (min 0, integer) so the recipe validator enforces it pre-run.
  4. Validate imported recipe JSON before loading.

Example fix

// before
const args = [4, -1, false];          // throws
// after
const args = [4, Math.max(0, Math.floor(start)), false];
Defensive patterns

Strategy: validation

Validate before calling

function startingAt(s) {
  if (!Number.isInteger(s) || s < 0) throw new RangeError("Starting at must be a non-negative integer");
  return s;
}
const safeStart = startingAt(args[1]);

Type guard

const isNonNegativeInt = (v) => Number.isInteger(v) && v >= 0;

Prevention

When it happens

Trigger: The 'Starting at' field is a negative number, a fraction (e.g. 1.5), NaN, or a non-numeric string. Reachable via imported recipe JSON, a cleared UI field coercing to NaN, or the Node API with an unguarded computed start.

Common situations: Hand-edited recipe JSON with a negative offset; a UI clear leaving the field empty and resolving to NaN; programmatic use where start went negative.

Related errors


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