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 the Extract LSB operation when the 'Bit' argument, after transformation (bit = 7 - args.pop()), falls outside the valid range [0, 7]. Each pixel channel value is 8 bits, so only bit positions 0–7 are valid for LSB extraction. The argument is popped from the end of the args array.
Source
Thrown at src/core/operations/ExtractLSB.mjs:86
* @param {Object[]} args
* @returns {byteArray}
*/
async run(input, args) {
if (!isImage(input))
throw new OperationError("Please enter a valid image file.");
const bit = 7 - args.pop(),
pixelOrder = args.pop(),
colours = args
.filter((option) => option !== "")
.map((option) => COLOUR_OPTIONS.indexOf(option)),
parsedImage = await Jimp.read(input),
width = parsedImage.bitmap.width,
height = parsedImage.bitmap.height,
rgba = parsedImage.bitmap.data;
if (bit < 0 || bit > 7) {
throw new OperationError(
"Error: Bit argument must be between 0 and 7",
);
}
let i,
combinedBinary = "";
if (pixelOrder === "Row") {
for (i = 0; i < rgba.length; i += 4) {
for (const colour of colours) {
combinedBinary += Utils.bin(rgba[i + colour])[bit];
}
}
} else {
let rowWidth;
const pixelWidth = width * 4;
for (let col = 0; col < width; col++) {
for (let row = 0; row < height; row++) {View on GitHub (pinned to 4290ea7539)
Solutions
- Set the 'Bit' argument to an integer between 0 and 7 inclusive.
- If using 0, note bit = 7 - 0 = 7 (most significant); if using 7, bit = 0 (least significant).
- Validate the argument before running the operation.
Example fix
// before: args 'Bit' = 10 -> bit = 7 - 10 = -3 -> error // after: args 'Bit' = 0 -> bit = 7 (valid range)
Defensive patterns
Strategy: validation
Validate before calling
// Validate Bit argument before calling ExtractLSB
const bitArg = args[5];
if (typeof bitArg !== 'number' || bitArg < 0 || bitArg > 7) {
throw new Error('Bit argument must be an integer between 0 and 7');
} Type guard
function isValidBitArg(bit) {
return Number.isInteger(bit) && bit >= 0 && bit <= 7;
} Prevention
- Restrict the Bit argument to integers 0–7.
- Validate argument bounds before recipe execution.
- Remember bit is internally transformed (7 - arg), so raw values 0–7 map inversely.
When it happens
Trigger: async run(input, args) where the computed bit value (7 - args[5], the 'Bit' number argument) is less than 0 or greater than 7. This means the raw 'Bit' argument was > 7 or < 0 before the 7-N transformation.
Common situations: User enters a Bit value of 8 or higher, or a negative number, in the operation's 'Bit' argument field. Also if a recipe programmatically supplies an out-of-range bit index.
Related errors
- Please enter a valid image file.
- Please enter a valid image file.
- Unsupported Mode: (${mode})
- Invalid file type.
- Invalid file type.
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/bf9f710b52c3a8c2.
Report an issue: GitHub.