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
Take Nth Bytes requires the 'Starting at' argument (start) to be a non-negative integer. The guard rejects fractional values and any value below 0, since a negative or fractional start offset has no defined meaning for byte indexing.
Source
Thrown at src/core/operations/TakeNthBytes.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("'Take 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
- Enter a zero-or-greater integer such as 0, 5, or 100 for 'Starting at'.
- Use 0 to start from the first byte.
- Remove any negative sign or fractional part from the field.
Example fix
// before: args[1] (Starting at) = -3 -> throws // after: args[1] (Starting at) = 3 -> begins sampling at byte index 3
Defensive patterns
Strategy: type-guard
Validate before calling
const start = args[1];
if (!(Number.isInteger(start) && start >= 0)) {
throw new Error("'Starting at' must be >= 0 integer");
} Type guard
const isNonNegInt = v => Number.isInteger(v) && v >= 0;
Try / catch
try { takeNthBytes(input, n, start, eachLine); }
catch (e) { if (/Starting at/.test(e.message)) { /* set start to 0 */ } else throw e; } Prevention
- Default the start field to 0.
- Use Number.isInteger to guard offsets.
- Reject negative offsets in form validation.
When it happens
Trigger: Passing a negative number or a non-integer for the 'Starting at' argument, or a NaN/string that fails the parseInt identity test.
Common situations: Entering -1 intending 'from the end' (not supported), leaving a decimal, or supplying an empty value that resolves to an invalid offset.
Related errors
- 'Take every' must be a positive integer.
- Width must be a positive integer
- ${this.name} must be an integer.
- Byte length must be a positive integer
- L must be non-negative
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/3b8255046d4dcadc.
Report an issue: GitHub.