feat: implement bad chat packet handling

This commit is contained in:
izzy 2026-03-07 18:10:32 -05:00
parent 0a8b0cb406
commit d31479a0ab
2 changed files with 24 additions and 2 deletions

View file

@ -2921,7 +2921,16 @@ void ClientConnection::handleContainerOpen(shared_ptr<ContainerOpenPacket> packe
case ContainerOpenPacket::LARGE_CHEST: chestString = IDS_CHEST_LARGE; break; case ContainerOpenPacket::LARGE_CHEST: chestString = IDS_CHEST_LARGE; break;
case ContainerOpenPacket::ENDER_CHEST: chestString = IDS_TILE_ENDERCHEST; break; case ContainerOpenPacket::ENDER_CHEST: chestString = IDS_TILE_ENDERCHEST; break;
case ContainerOpenPacket::CONTAINER: chestString = IDS_CHEST; break; case ContainerOpenPacket::CONTAINER: chestString = IDS_CHEST; break;
default: assert(false); chestString = -1; break; default:
throw IOException(L"ClientConnection::handleContainerOpen - invalid container type");
}
// izzint - surprised how little checks are here
const int MAX_CONTAINER_SIZE = 54; // double chest should be max, right?
if (packet->size < 0 || packet->size > MAX_CONTAINER_SIZE) {
throw IOException(L"ClientConnection::handleContainerOpen - invalid container size");
} }
if( player->openContainer(shared_ptr<SimpleContainer>( new SimpleContainer(chestString, packet->title, packet->customName, packet->size) ))) if( player->openContainer(shared_ptr<SimpleContainer>( new SimpleContainer(chestString, packet->title, packet->customName, packet->size) )))

View file

@ -43,12 +43,25 @@ ChatPacket::ChatPacket(const wstring& message, EChatPacketMessage type, int sour
// Read chat packet (throws IOException) // Read chat packet (throws IOException)
void ChatPacket::read(DataInputStream *dis) void ChatPacket::read(DataInputStream *dis)
{ {
m_messageType = (EChatPacketMessage) dis->readShort(); // izzint - TODO: i could see this validation being hardcoded becoming
// a problem for people who want to expand on chat types, plz review!
short msgType = dis->readShort();
if (msgType < e_ChatCustom || msgType > e_ChatCommandTeleportToMe)
{
throw IOException(L"ChatPacket::read - invalid chat type");
}
m_messageType = static_cast<EChatPacketMessage>(msgType);
short packedCounts = dis->readShort(); short packedCounts = dis->readShort();
int stringCount = (packedCounts >> 4) & 0xF; int stringCount = (packedCounts >> 4) & 0xF;
int intCount = (packedCounts >> 0) & 0xF; int intCount = (packedCounts >> 0) & 0xF;
// izzint - again, why didn't 4j patch this out??
if (stringCount > 15 || intCount > MAX_LENGTH)
{
throw IOException(L"ChatPacket::read - too many string arguments");
}
for(int i = 0; i < stringCount; i++) for(int i = 0; i < stringCount; i++)
{ {
m_stringArgs.push_back(readUtf(dis, MAX_LENGTH)); m_stringArgs.push_back(readUtf(dis, MAX_LENGTH));