aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Packet.cpp
diff options
context:
space:
mode:
authorLoki Rautio <lokirautio@gmail.com>2026-03-09 04:46:56 -0500
committerLoki Rautio <lokirautio@gmail.com>2026-03-09 04:46:56 -0500
commita358a3caaee2a4781f910cfb440bd822ae73a7e5 (patch)
tree638ff44db51c8e27826e56bacb5af764f98ef2d0 /Minecraft.World/Packet.cpp
parentd557ca2dfba5ffcca99ceb41b07d149f871964b5 (diff)
Revert accidentally pushed "LCEMP RCE fixes"
This reverts commit d557ca2dfba5ffcca99ceb41b07d149f871964b5.
Diffstat (limited to 'Minecraft.World/Packet.cpp')
-rw-r--r--Minecraft.World/Packet.cpp50
1 files changed, 30 insertions, 20 deletions
diff --git a/Minecraft.World/Packet.cpp b/Minecraft.World/Packet.cpp
index 05bf932d..129024b7 100644
--- a/Minecraft.World/Packet.cpp
+++ b/Minecraft.World/Packet.cpp
@@ -267,12 +267,8 @@ void Packet::updatePacketStatsPIX()
shared_ptr<Packet> Packet::getPacket(int id)
{
- auto it = idToCreateMap.find(id);
- if (it == idToCreateMap.end())
- {
- return nullptr;
- }
- return it->second();
+ // 4J: Removed try/catch
+ return idToCreateMap[id]();
}
void Packet::writeBytes(DataOutputStream *dataoutputstream, byteArray bytes)
@@ -338,11 +334,30 @@ shared_ptr<Packet> Packet::readPacket(DataInputStream *dis, bool isServer) // th
if ((isServer && serverReceivedPackets.find(id) == serverReceivedPackets.end()) || (!isServer && clientReceivedPackets.find(id) == clientReceivedPackets.end()))
{
- return nullptr;
+ app.DebugPrintf("*** BAD PACKET ID %d (0x%02X) isServer=%d totalPacketsRead=%d\n", id, id, isServer ? 1 : 0, s_packetCount);
+ app.DebugPrintf("*** Last %d good packet IDs (oldest first): ", 8);
+ for (int dbg = 0; dbg < 8; dbg++)
+ {
+ int idx = (s_lastIdPos + dbg) % 8;
+ app.DebugPrintf("%d ", s_lastIds[idx]);
+ }
+ app.DebugPrintf("\n");
+ // Dump the next 32 bytes from the stream to see what follows
+ app.DebugPrintf("*** Next bytes in stream: ");
+ for (int dbg = 0; dbg < 32; dbg++)
+ {
+ int b = dis->read();
+ if (b == -1) { app.DebugPrintf("[EOS] "); break; }
+ app.DebugPrintf("%02X ", b);
+ }
+ app.DebugPrintf("\n");
+ __debugbreak();
+ assert(false);
+ // throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
}
packet = getPacket(id);
- if (packet == nullptr) return nullptr;//throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
+ if (packet == nullptr) assert(false);//throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id));
s_lastIds[s_lastIdPos] = id;
s_lastIdPos = (s_lastIdPos + 1) % 8;
@@ -403,9 +418,11 @@ wstring Packet::readUtf(DataInputStream *dis, int maxLength) // throws IOExcepti
{
short stringLength = dis->readShort();
- if (stringLength > maxLength || stringLength <= 0)
+ if (stringLength > maxLength)
{
- return L"";
+ wstringstream stream;
+ stream << L"Received string length longer than maximum allowed (" << stringLength << " > " << maxLength << ")";
+ assert(false);
// throw new IOException( stream.str() );
}
if (stringLength < 0)
@@ -514,7 +531,7 @@ shared_ptr<ItemInstance> Packet::readItem(DataInputStream *dis)
{
shared_ptr<ItemInstance> item = nullptr;
int id = dis->readShort();
- if (id >= 0 && id < 32000) // todo: should turn Item::ITEM_NUM_COUNT into a global define
+ if (id >= 0)
{
int count = dis->readByte();
int damage = dis->readShort();
@@ -552,16 +569,9 @@ void Packet::writeItem(shared_ptr<ItemInstance> item, DataOutputStream *dos)
CompoundTag *Packet::readNbt(DataInputStream *dis)
{
int size = dis->readShort();
- if (size <= 0) return nullptr;
-
- const int MAX_NBT_SIZE = 32767;
- if (size > MAX_NBT_SIZE) return nullptr;
+ if (size < 0) return nullptr;
byteArray buff(size);
- if (!dis->readFully(buff))
- {
- delete [] buff.data;
- return nullptr;
- }
+ dis->readFully(buff);
CompoundTag *result = (CompoundTag *) NbtIo::decompress(buff);
delete [] buff.data;
return result;