From 482ca6b3c44649bc560aea5d86ca2c30d3abcd6b Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Thu, 1 Nov 2018 13:20:46 +0000 Subject: [PATCH 1/2] Use bytearray to accumulate bytes from gzip --- src/urllib3/response.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) From b0060136667a25877c09201738b9e75f4cb67bd7 Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Thu, 1 Nov 2018 13:22:55 +0000 Subject: [PATCH 2/2] Add changelog entry --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) 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 #)