From 0aeba3be0224a930f6ffef254ed12b41303a86d7 Mon Sep 17 00:00:00 2001 From: "Seth M. Larson" Date: Thu, 1 Nov 2018 10:47:15 -0500 Subject: [PATCH] Use bytearray to accumulate bytes from gzip (#1468) --- CHANGES.rst | 2 ++ src/urllib3/response.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4d70f4da99..f6dc184bb8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,8 @@ Changes dev (master) ------------ +* Remove quadratic behavior within ``GzipDecoder.decompress()`` (Issue #1467) + * ... [Short description of non-trivial change.] (Issue #) diff --git a/src/urllib3/response.py b/src/urllib3/response.py index f0cfbb5499..c112690b0a 100644 --- a/src/urllib3/response.py +++ b/src/urllib3/response.py @@ -69,9 +69,9 @@ def __getattr__(self, name): return getattr(self._obj, name) def decompress(self, data): - ret = b'' + ret = bytearray() if self._state == GzipDecoderState.SWALLOW_DATA or not data: - return ret + return bytes(ret) while True: try: ret += self._obj.decompress(data) @@ -81,11 +81,11 @@ def decompress(self, data): self._state = GzipDecoderState.SWALLOW_DATA if previous_state == GzipDecoderState.OTHER_MEMBERS: # Allow trailing garbage acceptable in other gzip clients - return ret + return bytes(ret) raise data = self._obj.unused_data if not data: - return ret + return bytes(ret) self._state = GzipDecoderState.OTHER_MEMBERS self._obj = zlib.decompressobj(16 + zlib.MAX_WBITS)