gchq/CyberChef · error · OperationError

Need 8 bytes for a UDP Header

Error message

Need 8 bytes for a UDP Header

What it means

The UDP header is fixed-size at exactly 8 bytes: source port, destination port, length, and checksum (2 bytes each). Parse UDP wraps the decoded input in a Stream and requires at least 8 bytes before reading those fields; fewer bytes means the header is incomplete and reading would underflow.

Source

Thrown at src/core/operations/ParseUDP.mjs:59

    /**
     * @param {string} input
     * @param {Object[]} args
     * @returns {Object}
     */
    run(input, args) {
        const format = args[0];

        if (format === "Hex") {
            input = fromHex(input);
        } else if (format === "Raw") {
            input = Utils.strToArrayBuffer(input);
        } else {
            throw new OperationError("Unrecognised input format.");
        }

        const s = new Stream(new Uint8Array(input));
        if (s.length < 8) {
            throw new OperationError("Need 8 bytes for a UDP Header");
        }

        // Parse Header
        const UDPPacket = {
            "Source port": s.readInt(2),
            "Destination port": s.readInt(2),
            "Length": s.readInt(2),
            "Checksum": "0x" + toHexFast(s.getBytes(2))
        };
        // Parse data if present
        if (s.hasMore()) {
            UDPPacket.Data = "0x" + toHexFast(s.getBytes(UDPPacket.Length - 8));
        }

        return UDPPacket;
    }

    /**

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide at least 8 bytes of a UDP header (16 hex characters for 'Hex' format).
  2. Match the 'Input format' arg to your data ('Hex' vs 'Raw').
  3. Strip IP/lower-layer headers so input begins at the UDP header.
  4. Verify the bytes actually carry UDP (IP protocol 17) before parsing.

Example fix

// before: payload only
run("68656c6c6f", ["Hex"]);  // 5 bytes -> throws

// after: 8-byte UDP header
run("00350035...", ["Hex"]);  // >= 8 bytes
Defensive patterns

Strategy: validation

Validate before calling

const FORMAT = args[0];
const bytes = FORMAT === "Hex" ? Buffer.from(input, "hex") : Buffer.from(input, "latin1");
if (bytes.length < 8) throw new Error(`Need >= 8 bytes of UDP header, got ${bytes.length}`);
return parseUdp.run(input, args);

Type guard

function isUdpHeaderLength(format, input) {
  const bytes = format === "Hex" ? Buffer.from(input, "hex") : Buffer.from(input, "latin1");
  return bytes.length >= 8;
}

Try / catch

try {
  return parseUdp.run(input, [format]);
} catch (e) {
  if (e.message === "Need 8 bytes for a UDP Header") {
    // prompt for the full 8-byte header
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling ParseUDP.run with input that decodes to fewer than 8 bytes: a Hex string shorter than 16 hex chars, or a Raw string shorter than 8 chars. Also when the wrong 'Input format' is chosen so the decoded length is wrong, or when payload-only / lower-layer data is supplied.

Common situations: Pasting only the UDP payload; supplying a full IP packet expecting the op to find the UDP header; selecting the wrong input format causing mis-decode; truncated packet data.

Related errors


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