Skip to content

Commit

Permalink
Fix IndexOutOfBoundsException for unexpected EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesbraun committed Oct 6, 2023
1 parent 60d6dad commit c68dac4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/rv/comm/rcssserver/ServerComm.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@ private String readMessage() throws IOException
// read from stream until all bytes in message are read
byte[] buf = new byte[length];
int bytesRead = 0;
while (bytesRead < length)
bytesRead += in.read(buf, bytesRead, length - bytesRead);
while (bytesRead < length) {
int tmp = in.read(buf, bytesRead, length - bytesRead);
if (tmp < 0) {
// Unexpected EOF
return null;
}
bytesRead += tmp;
}

return new String(buf);
}
Expand Down

0 comments on commit c68dac4

Please sign in to comment.