websocket icon indicating copy to clipboard operation
websocket copied to clipboard

bug in decode payload length

Open dawud-tan opened this issue 10 years ago • 0 comments

Hello Mr. Blink, your code line 430 as shown in this link https://github.com/blinkdog/websocket/blob/master/src/main/java/com/pmeade/websocket/io/WebSocketServerInputStream.java#L430

for (int i = 0; i < NUM_OCTET_64; i++) {
                payloadLength |=
                    inputStream.read() << (NUM_OCTET_64 - 1 - i) * OCTET;
            }

the result of inputStream.read() should be casted to long first, since bitwise OR between Long number and Integer number will result in Integer number. you may check this code snippet

long payloadLength = 0L;
int[] testData = new int[]{1,1,1,1,1,1,1,1};
for(int i=0; i<8; i++){
    long byteN = testData[i];
    payloadLength = payloadLength | byteN << (7 - i) * 8;
    System.out.print("i[" + i + "] payloadLength: ");
    printBinaryform(payloadLength);
    System.out.print("\r\n="+payloadLength);
    System.out.println();
}

following is the output of code above: long

long payloadLength = 0L;
int[] testData = new int[]{1,1,1,1,1,1,1,1};
for(int i=0; i<8; i++){
    payloadLength = payloadLength | testData[i] << (7 - i) * 8;
    System.out.print("i[" + i + "] payloadLength: ");
    printBinaryform(payloadLength);
    System.out.print("\r\n="+payloadLength);
    System.out.println();
}

The output of code above: integer

dawud-tan avatar Nov 05 '15 01:11 dawud-tan