Skip to content

bug in decode payload length #3

@dawud-tan

Description

@dawud-tan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions