gchq/CyberChef · error · OperationError
Error: Bit argument must be between 0 and 7
Error message
Error: Bit argument must be between 0 and 7
What it means
Thrown by 'View Bit Plane' when the bit-plane argument is outside 0-7. The bit argument selects one of the 8 bits of a colour channel; values outside that range have no valid bit index (the code computes bitIndex = 7 - bit).
Source
Thrown at src/core/operations/ViewBitPlane.mjs:69
async run(input, args) {
if (!isImage(input))
throw new OperationError("Please enter a valid image file.");
const [colour, bit] = args;
let parsedImage;
try {
parsedImage = await Jimp.read(input);
} catch (err) {
throw new OperationError(`Error loading image. (${err})`);
}
const width = parsedImage.bitmap.width,
height = parsedImage.bitmap.height,
colourIndex = COLOUR_OPTIONS.indexOf(colour),
bitIndex = 7 - bit;
if (bit < 0 || bit > 7) {
throw new OperationError(
"Error: Bit argument must be between 0 and 7",
);
}
let pixel, bin, newPixelValue;
parsedImage.scan(0, 0, width, height, function (x, y, idx) {
pixel = this.bitmap.data[idx + colourIndex];
bin = Utils.bin(pixel);
newPixelValue = 255;
if (bin.charAt(bitIndex) === "1") newPixelValue = 0;
for (let i = 0; i < 3; i++) {
this.bitmap.data[idx + i] = newPixelValue;
}
this.bitmap.data[idx + 3] = 255;
});View on GitHub (pinned to 4290ea7539)
Solutions
- Set the bit argument to an integer in the range 0-7 inclusive.
- If your convention numbers bits from the MSB, map it to 7 minus that index.
- Validate recipe JSON before running when bit is supplied externally.
Example fix
// before viewBitPlane(input, ["Red", 8]); // after viewBitPlane(input, ["Red", 7]);
Defensive patterns
Strategy: validation
Validate before calling
if (!Number.isInteger(bit) || bit < 0 || bit > 7) {
throw new Error(`Bit argument must be an integer 0-7, got ${bit}`);
} Type guard
function isValidBitPlane(b) { return Number.isInteger(b) && b >= 0 && b <= 7; } Prevention
- Clamp bit index to 0-7 when building recipes programmatically.
- Account for MSB-vs-LSB numbering conventions.
When it happens
Trigger: Setting the bit argument below 0 or above 7 via the Node API or a hand-edited recipe. In the UI the control is a number spinner; a manually crafted recipe can carry an out-of-range value.
Common situations: Programmatically building a recipe with an off-by-one or negative bit index, or mis-translating a 'bit significance' convention (LSB=0 vs MSB=0).
Related errors
- ${this.name} must be greater than or equal to ${this.min}.
- ${this.name} must be less than or equal to ${this.max}.
- IPv4 CIDR must be less than 32
- IPv6 CIDR must be less than 128
- Block out of range.
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/370e3ee651445af0.
Report an issue: GitHub.