Fixed crash if we get a short read from the Xbox One controller

This commit is contained in:
Cameron Gutman 2020-12-24 11:59:33 -06:00
parent 57b507ad50
commit bdac2df4b9
2 changed files with 12 additions and 2 deletions

View File

@ -66,8 +66,8 @@ public class Xbox360Controller extends AbstractXboxController {
@Override
protected boolean handleRead(ByteBuffer buffer) {
if (buffer.limit() < 14) {
LimeLog.severe("Read too small: "+buffer.limit());
if (buffer.remaining() < 14) {
LimeLog.severe("Read too small: "+buffer.remaining());
return false;
}

View File

@ -101,11 +101,21 @@ public class XboxOneController extends AbstractXboxController {
switch (buffer.get())
{
case 0x20:
if (buffer.remaining() < 17) {
LimeLog.severe("XBone button/axis read too small: "+buffer.remaining());
return false;
}
buffer.position(buffer.position()+3);
processButtons(buffer);
return true;
case 0x07:
if (buffer.remaining() < 4) {
LimeLog.severe("XBone mode read too small: "+buffer.remaining());
return false;
}
// The Xbox One S controller needs acks for mode reports otherwise
// it retransmits them forever.
if (buffer.get() == 0x30) {