From 7eef61bfdef8176d89649fc6846041d807d8b2fb Mon Sep 17 00:00:00 2001 From: TheSnoozer Date: Tue, 8 Aug 2017 20:29:25 +0200 Subject: [PATCH] use 'zlib.decompressobj' to handle the 'faulty' compression correctly as suggested in https://github.com/ammaraskar/pyCraft/pull/68 --- minecraft/networking/connection.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/minecraft/networking/connection.py b/minecraft/networking/connection.py index 91aa612..36ca7d9 100644 --- a/minecraft/networking/connection.py +++ b/minecraft/networking/connection.py @@ -2,7 +2,7 @@ from __future__ import print_function from collections import deque from threading import Lock -from zlib import decompress +import zlib import threading import socket import time @@ -437,7 +437,9 @@ class PacketReactor(object): if self.connection.options.compression_enabled: decompressed_size = VarInt.read(packet_data) if decompressed_size > 0: - decompressed_packet = decompress(packet_data.read()) + decompressor = zlib.decompressobj() + decompressed_packet = decompressor.decompress( + packet_data.read()) assert len(decompressed_packet) == decompressed_size, \ 'decompressed length %d, but expected %d' % \ (len(decompressed_packet), decompressed_size)