Fix MyFreeCams websocket message parsing

This commit is contained in:
0xboobface 2020-07-03 18:56:59 +02:00
parent 4205cb6ff2
commit d2c2cb476b
1 changed files with 6 additions and 4 deletions

View File

@ -455,17 +455,19 @@ public class MyFreeCamsClient {
}
private Message parseMessage(StringBuilder msgBuffer) throws UnsupportedEncodingException {
if (msgBuffer.length() < 4) {
int packetLengthBytes = 6;
if (msgBuffer.length() < packetLengthBytes) {
// packet size not transmitted completely
return null;
} else {
try {
int packetLength = Integer.parseInt(msgBuffer.substring(0, 4));
if (packetLength > msgBuffer.length() - 4) {
int packetLength = Integer.parseInt(msgBuffer.substring(0, packetLengthBytes));
if (packetLength > msgBuffer.length() - packetLengthBytes) {
// packet not complete
return null;
} else {
msgBuffer.delete(0, 4);
LOG.trace("<-- {}", msgBuffer);
msgBuffer.delete(0, packetLengthBytes);
StringBuilder rawMessage = new StringBuilder(msgBuffer.substring(0, packetLength));
int type = parseNextInt(rawMessage);
int sender = parseNextInt(rawMessage);