Fix errors caused by the "uncompressed data length" field of compressed packets being erroneously written as the compressed data length.

This commit is contained in:
joo 2016-09-27 11:32:39 +01:00
parent c4ed8e6d68
commit 03565e24c8
2 changed files with 12 additions and 10 deletions

View File

@ -335,11 +335,12 @@ class PacketReactor(object):
packet_data.reset_cursor()
if self.connection.options.compression_enabled:
compressed_size = VarInt.read(packet_data)
if compressed_size > 0:
decompressed_packet = decompress(
packet_data.read(compressed_size))
decompressed_size = VarInt.read(packet_data)
if decompressed_size > 0:
decompressed_packet = decompress(packet_data.read())
assert len(decompressed_packet) == decompressed_size, \
'decompressed length %d, but expected %d' % \
(len(decompressed_packet), decompressed_size)
packet_data.reset()
packet_data.send(decompressed_packet)
packet_data.reset_cursor()

View File

@ -18,10 +18,10 @@ class PacketBuffer(object):
"""
self.bytes.write(value)
def read(self, length):
def read(self, length=None):
return self.bytes.read(length)
def recv(self, length):
def recv(self, length=None):
return self.read(length)
def reset(self):
@ -123,10 +123,11 @@ class Packet(object):
if compression_threshold is not None:
if len(packet_buffer.get_writable()) > compression_threshold != -1:
# compress the current payload
compressed_data = compress(packet_buffer.get_writable())
packet_data = packet_buffer.get_writable()
compressed_data = compress(packet_data)
packet_buffer.reset()
# write out the length of the compressed payload
VarInt.send(len(compressed_data), packet_buffer)
# write out the length of the uncompressed payload
VarInt.send(len(packet_data), packet_buffer)
# write the compressed payload itself
packet_buffer.send(compressed_data)
else: