Liveview: add some sanity checks to the incoming data lenghts

This commit is contained in:
Daniele Gobbetti 2016-12-07 13:09:15 +01:00
parent 4eb56eb9ca
commit 6a09023c24
1 changed files with 6 additions and 1 deletions

View File

@ -180,11 +180,16 @@ public class LiveviewIoThread extends GBDeviceIoThread {
incoming = new byte[1]; incoming = new byte[1];
break; break;
case HEADER_LEN: case HEADER_LEN:
int headerSize = 0xff & incoming[0];
if (headerSize < 0)
throw new IOException();
state = ReaderState.HEADER; state = ReaderState.HEADER;
incoming = new byte[incoming[0]]; incoming = new byte[headerSize];
break; break;
case HEADER: case HEADER:
int payloadSize = getLastInt(msgStream); int payloadSize = getLastInt(msgStream);
if (payloadSize < 0 || payloadSize > 8000) //this will possibly be changed in the future
throw new IOException();
state = ReaderState.PAYLOAD; state = ReaderState.PAYLOAD;
incoming = new byte[payloadSize]; incoming = new byte[payloadSize];
break; break;