Skip to content

Commit dfcc68d

Browse files
lwahlmeierjentfoo
authored andcommitted
fixed buffer issues with websockets
1 parent 4efd506 commit dfcc68d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

protocol/src/main/java/org/threadly/litesockets/protocols/websocket/WSFrame.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ public class WSFrame {
1717
private final int frameLength;
1818

1919
protected WSFrame(final ByteBuffer bb) {
20-
frameLength = WSUtils.getFrameLength(bb);
20+
ByteBuffer sbb = bb.slice();
21+
frameLength = WSUtils.getFrameLength(sbb);
2122
if(frameLength < 0 || bb.remaining() < frameLength) {
2223
throw new IllegalStateException("Not enough data to make a WebSocketFrame");
2324
}
24-
this.bb = bb;
25+
this.bb = sbb;
2526
}
2627

2728
/**

protocol/src/main/java/org/threadly/litesockets/protocols/websocket/WSUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static int getFrameLength(final ByteBuffer bb) {
148148
* @return the size in the first length field.
149149
*/
150150
static byte getSmallLen(final ByteBuffer bb) {
151-
return (byte)(bb.get(1) & WSConstants.WS_SMALL_LENGTH_MASK);
151+
return (byte)(bb.get(bb.position()+1) & WSConstants.WS_SMALL_LENGTH_MASK);
152152
}
153153

154154
static int getLengthSize(final ByteBuffer bb) {
@@ -162,6 +162,6 @@ static int getLengthSize(final ByteBuffer bb) {
162162
}
163163

164164
private static boolean hasMask(final ByteBuffer bb) {
165-
return (bb.get(1) & WSConstants.UNSIGN_BYTE_MASK) >> WSConstants.STATIC_SEVEN == 1;
165+
return (bb.get(bb.position()+1) & WSConstants.UNSIGN_BYTE_MASK) >> WSConstants.STATIC_SEVEN == 1;
166166
}
167167
}

0 commit comments

Comments
 (0)