gchq/CyberChef · error · OperationError

Block out of range.

Error message

Block out of range.

What it means

Thrown by strToIpv4's parseBlocks when any octet, after parseInt base 10, falls outside 0-255. Note a quirk: parseInt of non-numeric text yields NaN, and NaN is neither <0 nor >255, so non-numeric octets slip through this guard (a latent bug). The check reliably catches out-of-range numeric octets like 256. OperationError.

Source

Thrown at src/core/lib/IP.mjs:312

    result += numBlocks[0] << 24;
    result += numBlocks[1] << 16;
    result += numBlocks[2] << 8;
    result += numBlocks[3];

    return result;

    /**
     * Converts a list of 4 numeric strings in the range 0-255 to a list of numbers.
     */
    function parseBlocks(blocks) {
        if (blocks.length !== 4)
            throw new OperationError("More than 4 blocks.");

        const numBlocks = [];
        for (let i = 0; i < 4; i++) {
            numBlocks[i] = parseInt(blocks[i], 10);
            if (numBlocks[i] < 0 || numBlocks[i] > 255)
                throw new OperationError("Block out of range.");
        }
        return numBlocks;
    }
}

/**
 * Converts an IPv4 address from numerical format to string format.
 *
 * @param {number} ipInt
 * @returns {string}
 *
 * @example
 * // returns "10.10.0.0"
 * ipv4ToStr(168427520);
 */
export function ipv4ToStr(ipInt) {
    const blockA = (ipInt >> 24) & 255,
        blockB = (ipInt >> 16) & 255,

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Validate each octet is a base-10 integer in [0,255] before calling strToIpv4 (also reject NaN/non-numeric).
  2. Use an IPv4 regex that bounds each octet to 0-255.
  3. Sanitise generated IP lists before parsing.

Example fix

// before
strToIpv4("10.0.0.256");

// after
strToIpv4("10.0.0.255");
Defensive patterns

Strategy: validation

Validate before calling

function assertIpv4Octets(ipStr) {
  const blocks = ipStr.split(".");
  if (blocks.length !== 4) throw new Error("Need exactly 4 octets");
  for (const b of blocks) {
    const n = Number.parseInt(b, 10);
    if (!Number.isInteger(n) || n < 0 || n > 255) {
      throw new Error(`Octet '${b}' out of range 0-255`);
    }
  }
}
assertIpv4Octets(ipStr);
strToIpv4(ipStr);

Type guard

const isIpv4InRange = ipStr =>
  ipStr.split(".").every(b => { const n = Number.parseInt(b, 10); return Number.isInteger(n) && n >= 0 && n <= 255; });

Try / catch

try {
  strToIpv4(ipStr);
} catch (err) {
  if (err instanceof OperationError && /Block out of range/.test(err.message)) {
    // an octet exceeded 255; correct the input
  } else throw err;
}

Prevention

When it happens

Trigger: Calling strToIpv4('1.2.3.256'), '1.2.3.-1', or '10.0.0.300'. Non-numeric junk in an octet may bypass this and produce NaN downstream instead.

Common situations: Typo producing an octet >255; negative value; leading-zero or decimal confusion; off-by-one in generated IPs.

Related errors


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