Skip to content

Commit d7afeb2

Browse files
markt-asfac000
authored andcommitted
java: websocket: Additional payload length validation
<https://bz.apache.org/bugzilla/show_bug.cgi?id=64563> Patch taken from <https://github.com/apache/tomcat/commit/1c1c77b0efb667cea80b532440b44cea1dc427c3.patch> [ Subject / message tweak - Andrew ] Signed-off-by: Andrew Clayton <[email protected]>
1 parent 5e7bc38 commit d7afeb2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/java/nginx/unit/websocket/WsFrameBase.java

+7
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ private boolean processRemainingHeader() throws IOException {
260260
} else if (payloadLength == 127) {
261261
payloadLength = byteArrayToLong(inputBuffer.array(),
262262
inputBuffer.arrayOffset() + inputBuffer.position(), 8);
263+
// The most significant bit of those 8 bytes is required to be zero
264+
// (see RFC 6455, section 5.2). If the most significant bit is set,
265+
// the resulting payload length will be negative so test for that.
266+
if (payloadLength < 0) {
267+
throw new WsIOException(
268+
new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.payloadMsbInvalid")));
269+
}
263270
inputBuffer.position(inputBuffer.position() + 8);
264271
}
265272
if (Util.isControl(opCode)) {

0 commit comments

Comments
 (0)