Fix IndexOutOfBoundsException issues.

This commit is contained in:
Captain ALM 2023-05-23 13:06:29 +01:00
parent b0bb4057f6
commit b8179ca1c0
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1
3 changed files with 88 additions and 75 deletions

View File

@ -237,6 +237,7 @@ public class EncryptedPacket implements IStreamedPacket, IInternalCache {
public void loadPayload(byte[] packetData) throws PacketException {
if (packetData == null) throw new NullPointerException("packetData is null");
synchronized (slock) {
try {
int index = 1;
int cipherLenCache = (packetData[index++] & 0xff) * 16777216;
@ -246,7 +247,8 @@ public class EncryptedPacket implements IStreamedPacket, IInternalCache {
if (cipherLenCache < 1) throw new PacketException("cipher length less than 1");
byte[] cipherSettingsCache = new byte[cipherLenCache];
System.arraycopy(packetData, index, cipherSettingsCache, 0, cipherLenCache); index += cipherLenCache;
System.arraycopy(packetData, index, cipherSettingsCache, 0, cipherLenCache);
index += cipherLenCache;
try {
cipherFactory.setSettings(cipherSettingsCache);
} catch (CipherException e) {
@ -285,6 +287,9 @@ public class EncryptedPacket implements IStreamedPacket, IInternalCache {
} finally {
if (!useCache) encryptedCache = null;
}
} catch (IndexOutOfBoundsException e) {
throw new PacketException(e);
}
}
}

View File

@ -139,6 +139,7 @@ public class NetworkEncryptionCipherPacket implements IStreamedPacket, IAcknowle
if (packetData == null) throw new NullPointerException("packetData is null");
if (packetData.length < 5) throw new PacketException("no data");
synchronized (slock) {
try {
acknowledgement = (packetData[0] == 1);
if (!acknowledgement && packetData[0] != 0) acknowledgement = null;
int index = 1;
@ -166,6 +167,9 @@ public class NetworkEncryptionCipherPacket implements IStreamedPacket, IAcknowle
ciphers[i] = "";
}
}
} catch (IndexOutOfBoundsException e) {
throw new PacketException(e);
}
}
}

View File

@ -106,6 +106,7 @@ public class NetworkEncryptionUpgradePacket implements IPacket, IAcknowledgement
if (packetData == null) throw new NullPointerException("packetData is null");
if (packetData.length < 2) throw new PacketException("no data");
synchronized (slock) {
try {
acknowledgement = (packetData[0] == 1);
if (!acknowledgement && packetData[0] != 0) acknowledgement = null;
@ -121,6 +122,9 @@ public class NetworkEncryptionUpgradePacket implements IPacket, IAcknowledgement
throw new PacketException(e);
}
}
} catch (IndexOutOfBoundsException e) {
throw new PacketException(e);
}
}
}