Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/java/nginx/unit/websocket/WsFrameBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ private boolean processRemainingHeader() throws IOException {
} else if (payloadLength == 127) {
payloadLength = byteArrayToLong(inputBuffer.array(),
inputBuffer.arrayOffset() + inputBuffer.position(), 8);
// The most significant bit of those 8 bytes is required to be zero
// (see RFC 6455, section 5.2). If the most significant bit is set,
// the resulting payload length will be negative so test for that.
if (payloadLength < 0) {
throw new WsIOException(
new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.payloadMsbInvalid")));
}
inputBuffer.position(inputBuffer.position() + 8);
}
if (Util.isControl(opCode)) {
Expand Down Expand Up @@ -670,7 +677,7 @@ protected static long byteArrayToLong(byte[] b, int start, int len) throws IOExc
int shift = 0;
long result = 0;
for (int i = start + len - 1; i >= start; i--) {
result = result + ((b[i] & 0xFF) << shift);
result = result + ((b[i] & 0xFFL) << shift);
shift += 8;
}
return result;
Expand Down
Loading