mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-21 01:01:41 +00:00
Add check for packet of incorrect length (#629)
Co-authored-by: Matt <matthew.morley.ca@gmail.com>
This commit is contained in:
@@ -129,6 +129,9 @@ public class Packet {
|
||||
* @return A decoded byte from the packet.
|
||||
*/
|
||||
public byte decodeByte() {
|
||||
if (packetData.length < readPos) {
|
||||
return '\0';
|
||||
}
|
||||
return packetData[readPos++];
|
||||
}
|
||||
|
||||
@@ -138,6 +141,9 @@ public class Packet {
|
||||
* @return A decoded int from the packet.
|
||||
*/
|
||||
public int decodeInt() {
|
||||
if (packetData.length < readPos + 3) {
|
||||
return 0;
|
||||
}
|
||||
return (0xff & packetData[readPos++]) << 24
|
||||
| (0xff & packetData[readPos++]) << 16
|
||||
| (0xff & packetData[readPos++]) << 8
|
||||
@@ -150,6 +156,9 @@ public class Packet {
|
||||
* @return A decoded double from the packet.
|
||||
*/
|
||||
public double decodeDouble() {
|
||||
if (packetData.length < (readPos + 7)) {
|
||||
return 0;
|
||||
}
|
||||
long data =
|
||||
(long) (0xff & packetData[readPos++]) << 56
|
||||
| (long) (0xff & packetData[readPos++]) << 48
|
||||
@@ -168,6 +177,9 @@ public class Packet {
|
||||
* @return A decoded boolean from the packet.
|
||||
*/
|
||||
public boolean decodeBoolean() {
|
||||
if (packetData.length < readPos) {
|
||||
return false;
|
||||
}
|
||||
return packetData[readPos++] == 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user