TooTallNate/Java-WebSocket · error · LimitExceededException

Payloadsize is to big...

Error message

Payloadsize is to big...

What it means

translateSingleFrameCheckLengthLimit throws LimitExceededException("Payloadsize is to big...") when a frame's decoded payload length exceeds Integer.MAX_VALUE. JavaWebsocket stores payloads in byte arrays/ByteBuffers, which cannot exceed the int range, so such frames cannot be handled.

Solutions

  1. Catch LimitExceededException and close the connection with a message-too-big / policy-violation close code (1009)
  2. Cap frame sizes at the sender so no single frame exceeds Integer.MAX_VALUE (and your maxFrameSize)
  3. Split large messages into multiple frames or use message size limits on both endpoints
  4. Treat it as untrusted input: validate peer frame sizes before accepting

Example fix

// before: no size guard, exception surfaces as connect loss
// after: configure and handle
Draft_6455 draft = new Draft_6455();
draft.setMaxFrameSize(1024 * 1024); // 1 MiB cap
// in listener:
} catch (LimitExceededException e) {
  webSocket.close(CloseFrame.TOOBIG, "frame too large");
}
Defensive patterns

Strategy: try-catch

Validate before calling

// reject impossible 64-bit lengths before the library does
long declaredLen = readFrameLength(header);
if (declaredLen > Integer.MAX_VALUE) failConnection(CloseFrame.TOOBIG);

Try / catch

try {
  startConnection();
} catch (LimitExceededException e) {
  webSocket.close(CloseFrame.TOOBIG, "frame too large");
}

Prevention

When it happens

Trigger: An incoming frame uses a 64-bit extended payload length whose value is > 2147483647; translateSingleFrame or translateSingleFramePayloadLength calls translateSingleFrameCheckLengthLimit and the length > Integer.MAX_VALUE branch fires.

Common situations: Malicious or broken peer announcing absurdly large frames; memory-corrupted length fields; fuzzer-generated traffic; attempting to receive multi-gigabyte single frames.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of TooTallNate/Java-WebSocket@afeacbf8c0 (2026-09-09). Data as JSON: /api/errors/2b084a6f51aa6304. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/org/java_websocket/drafts/Draft_6455.java:651

        bytes[i] = buffer.get(/*1 + i*/);
      }
      long length = new BigInteger(bytes).longValue();
      translateSingleFrameCheckLengthLimit(length);
      payloadlength = (int) length;
    }
    return new TranslatedPayloadMetaData(payloadlength, realpacketsize);
  }

  /**
   * Check if the frame size exceeds the allowed limit
   *
   * @param length the current payload length
   * @throws LimitExceededException if the payload length is to big
   */
  private void translateSingleFrameCheckLengthLimit(long length) throws LimitExceededException {
    if (length > Integer.MAX_VALUE) {
      log.trace("Limit exedeed: Payloadsize is to big...");
      throw new LimitExceededException("Payloadsize is to big...");
    }
    if (length > maxFrameSize) {
      log.trace("Payload limit reached. Allowed: {} Current: {}", maxFrameSize, length);
      throw new LimitExceededException("Payload limit reached.", maxFrameSize);
    }
    if (length < 0) {
      log.trace("Limit underflow: Payloadsize is to little...");
      throw new LimitExceededException("Payloadsize is to little...");
    }
  }

  /**
   * Check if the max packet size is smaller than the real packet size
   *
   * @param maxpacketsize  the max packet size
   * @param realpacketsize the real packet size
   * @throws IncompleteException if the maxpacketsize is smaller than the realpackagesize
   */

View on GitHub (pinned to afeacbf8c0)