diff options
author | Mattes D <github@xoft.cz> | 2016-01-10 15:36:15 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2016-01-10 15:36:15 +0100 |
commit | 7111154160ebd734779d2e278b8b9708791db7f0 (patch) | |
tree | 0aba3e7eab7e332796d464113c8f7d653405907d /src/Protocol/Protocol18x.cpp | |
parent | Merge pull request #2847 from cuberite/FixClangWarnings (diff) | |
parent | Fixed not working packet decompression (diff) | |
download | cuberite-7111154160ebd734779d2e278b8b9708791db7f0.tar cuberite-7111154160ebd734779d2e278b8b9708791db7f0.tar.gz cuberite-7111154160ebd734779d2e278b8b9708791db7f0.tar.bz2 cuberite-7111154160ebd734779d2e278b8b9708791db7f0.tar.lz cuberite-7111154160ebd734779d2e278b8b9708791db7f0.tar.xz cuberite-7111154160ebd734779d2e278b8b9708791db7f0.tar.zst cuberite-7111154160ebd734779d2e278b8b9708791db7f0.zip |
Diffstat (limited to 'src/Protocol/Protocol18x.cpp')
-rw-r--r-- | src/Protocol/Protocol18x.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 9b716ff92..d80e9d034 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -1834,39 +1834,44 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) } // Check packet for compression: - UInt32 CompressedSize = 0; + UInt32 UncompressedSize = 0; AString UncompressedData; if (m_State == 3) { UInt32 NumBytesRead = static_cast<UInt32>(m_ReceivedData.GetReadableSpace()); - m_ReceivedData.ReadVarInt(CompressedSize); - if (CompressedSize > PacketLen) + + if (!m_ReceivedData.ReadVarInt(UncompressedSize)) { - m_Client->Kick("Bad compression"); + m_Client->Kick("Compression packet incomplete"); return; } - if (CompressedSize > 0) + + NumBytesRead -= static_cast<UInt32>(m_ReceivedData.GetReadableSpace()); // How many bytes has the UncompressedSize taken up? + ASSERT(PacketLen > NumBytesRead); + PacketLen -= NumBytesRead; + + if (UncompressedSize > 0) { // Decompress the data: AString CompressedData; - if (!m_ReceivedData.ReadString(CompressedData, CompressedSize) || (InflateString(CompressedData.data(), CompressedSize, UncompressedData) != Z_OK)) + VERIFY(m_ReceivedData.ReadString(CompressedData, PacketLen)); + if (InflateString(CompressedData.data(), PacketLen, UncompressedData) != Z_OK) { m_Client->Kick("Compression failure"); return; } PacketLen = static_cast<UInt32>(UncompressedData.size()); - } - else - { - NumBytesRead -= static_cast<UInt32>(m_ReceivedData.GetReadableSpace()); // How many bytes has the CompressedSize taken up? - ASSERT(PacketLen > NumBytesRead); - PacketLen -= NumBytesRead; + if (PacketLen != UncompressedSize) + { + m_Client->Kick("Wrong uncompressed packet size given"); + return; + } } } // Move the packet payload to a separate cByteBuffer, bb: cByteBuffer bb(PacketLen + 1); - if (CompressedSize == 0) + if (UncompressedSize == 0) { // No compression was used, move directly VERIFY(m_ReceivedData.ReadToByteBuffer(bb, static_cast<size_t>(PacketLen))); |