Skip to content

Commit

Permalink
java: websocket: Additional payload length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf authored and ac000 committed Feb 21, 2025
1 parent 5e7bc38 commit d7afeb2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 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

0 comments on commit d7afeb2

Please sign in to comment.