gchq/CyberChef · error · OperationError

Invalid value

Error message

Invalid value

What it means

Thrown by base92Chr(val) in src/core/lib/Base92.mjs:19 when the numeric value passed in is outside the half-open range [0, 91). Base92's alphabet (as defined here) maps values 0..90 to characters: 0->'!', 1..61->'#'..'_', 62..90->'a'..'}'. A value below 0 or >= 91 has no corresponding character and indicates a bug in the caller or an upstream arithmetic overflow.

Source

Thrown at src/core/lib/Base92.mjs:19

/**
 * Base92 resources.
 *
 * @author sg5506844 [sg5506844@gmail.com]
 * @copyright Crown Copyright 2021
 * @license Apache-2.0
 */

import OperationError from "../errors/OperationError.mjs";

/**
 * Base92 alphabet char
 *
 * @param {number} val
 * @returns {number}
 */
export function base92Chr(val) {
    if (val < 0 || val >= 91) {
        throw new OperationError("Invalid value");
    }
    if (val === 0)
        return "!".charCodeAt(0);
    else if (val <= 61)
        return "#".charCodeAt(0) + val - 1;
    else
        return "a".charCodeAt(0) + val - 62;
}

/**
 * Base92 alphabet ord
 *
 * @param {string} val
 * @returns {number}
 */
export function base92Ord(val) {
    if (val === "!")
        return 0;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Range-check val before calling: if (val >= 0 && val < 91) base92Chr(val).
  2. Audit the caller's bit-packing math; valid Base92 digits are strictly 0..90.
  3. Use the project's higher-level Base92 encode operation instead of the low-level helper.
  4. If you see this from the standard operation, the input was not a clean byte array — normalize it first.

Example fix

// before - unchecked value
const ch = base92Chr(maybeNegativeOrLarge);

// after - guard the range
const ch = (maybeNegativeOrLarge >= 0 && maybeNegativeOrLarge < 91)
  ? base92Chr(maybeNegativeOrLarge)
  : null; // or throw your own error
Defensive patterns

Strategy: type-guard

Validate before calling

function safeBase92Chr(val) {
  if (typeof val !== 'number' || !Number.isInteger(val) || val < 0 || val >= 91) {
    throw new RangeError(`base92 digit out of range: ${val}`);
  }
  return base92Chr(val);
}

Type guard

function isValidBase92Digit(val) {
  return typeof val === 'number' && Number.isInteger(val) && val >= 0 && val < 91;
}

Try / catch

try {
  const code = base92Chr(digit);
} catch (e) {
  if (e instanceof OperationError && e.message === 'Invalid value') {
    // digit out of [0,91); fix upstream bit-packing
  }
}

Prevention

When it happens

Trigger: Direct call base92Chr(-1), base92Chr(91), base92Chr(100). Indirectly: the Base92 encoder computing a digit >= 91 from malformed input, e.g. a bit-packing routine that produced an out-of-range 7-bit value because the input byte array was corrupted or the encoder's accumulator logic was bypassed.

Common situations: Calling base92Chr directly with an unchecked loop index; a forked or hand-rolled Base92 encoder that mis-computes digit boundaries; feeding non-byte-array data (e.g. negative numbers from a signed-int source) into the encoder path.

Related errors


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