summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/gzip.py2
-rw-r--r--Lib/test/test_gzip.py7
-rw-r--r--Misc/NEWS3
3 files changed, 11 insertions, 1 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 8d21fe4..f934d4f 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -96,7 +96,7 @@ class _PaddedFile:
self._read -= len(prepend)
return
else:
- self._buffer = self._buffer[read:] + prepend
+ self._buffer = self._buffer[self._read:] + prepend
self._length = len(self._buffer)
self._read = 0
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index 5289407..b7a7e03 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -421,6 +421,13 @@ class TestGzip(BaseTest):
with gzip.GzipFile(fileobj=io.BytesIO(gzdata)) as f:
self.assertEqual(f.read(), b'Test')
+ def test_prepend_error(self):
+ # See issue #20875
+ with gzip.open(self.filename, "wb") as f:
+ f.write(data1)
+ with gzip.open(self.filename, "rb") as f:
+ f.fileobj.prepend()
+
class TestOpen(BaseTest):
def test_binary_modes(self):
uncompressed = data1 * 50
diff --git a/Misc/NEWS b/Misc/NEWS
index 4f7328c..68cb379 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -20,6 +20,9 @@ Core and Builtins
Library
-------
+- Issue #20875: Prevent possible gzip "'read' is not defined" NameError.
+ Patch by Claudiu Popa.
+
- Issue #11558: ``email.message.Message.attach`` now returns a more
useful error message if ``attach`` is called on a message for which
``is_multipart`` is False.