Skip to content

Commit

Permalink
Fix ArrayIndexOutOfBounds in NatsConnectionReader when gatherOp() is …
Browse files Browse the repository at this point in the history
…called which was caused by the websocket "close body" to be returned from the input stream.
  • Loading branch information
Brian Maher committed Nov 11, 2021
1 parent 2dd4359 commit 0c19373
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.io.IOException;
import java.io.InputStream;

import io.nats.client.support.WebsocketFrameHeader.OpCode;

public class WebsocketInputStream extends InputStream {
private byte[] buffer = new byte[WebsocketFrameHeader.MAX_FRAME_HEADER_SIZE];
private WebsocketFrameHeader header = new WebsocketFrameHeader();
Expand Down Expand Up @@ -59,6 +61,11 @@ public int read(byte[] buffer, int offset, int length) throws IOException {
return -1;
}
}
if (header.getOpCode() == OpCode.CLOSE) {
// Ignore the websocket close message body:
in.skip(header.getPayloadLength());
return -1;
}
length = in.read(buffer, offset, length);
if (-1 == length) {
return length;
Expand Down

0 comments on commit 0c19373

Please sign in to comment.