https://github.com/python/cpython/commit/d4b1d55006e54fd64132a7892b15d0852dc3b74a
commit: d4b1d55006e54fd64132a7892b15d0852dc3b74a
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-10-10T13:35:31+03:00
summary:

[3.15] gh-158169: Clear `zlib.Decompress.unconsumed_tail` at end of stream 
(GH-158177) (GH-158228)

(cherry picked from commit 8122ff4818f418e8ae984cf6964215689b00808d)

Co-authored-by: GruffElixir <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-09-25-22-15-54.gh-issue-158169.ZlibTail.rst
M Lib/test/test_zlib.py
M Modules/zlibmodule.c

diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
index 024c58e7cabd79..43941dd37d7106 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -762,6 +762,18 @@ def test_decompress_unused_data(self):
                 self.assertEqual(dco.unconsumed_tail, b'')
                 self.assertEqual(dco.unused_data, remainder)
 
+    def test_decompress_unconsumed_tail_after_eof(self):
+        source = b'abcdefghijklmnopqrstuvwxyz'
+        remainder = b'0123456789'
+        dco = zlib.decompressobj()
+        data = dco.decompress(zlib.compress(source) + remainder, 1)
+        data += dco.decompress(dco.unconsumed_tail)
+
+        self.assertTrue(dco.eof)
+        self.assertEqual(data, source)
+        self.assertEqual(dco.unconsumed_tail, b'')
+        self.assertEqual(dco.unused_data, remainder)
+
     # issue27164
     def test_decompress_raw_with_dictionary(self):
         zdict = b'abcdefghijklmnopqrstuvwxyz'
diff --git 
a/Misc/NEWS.d/next/Library/2026-09-25-22-15-54.gh-issue-158169.ZlibTail.rst 
b/Misc/NEWS.d/next/Library/2026-09-25-22-15-54.gh-issue-158169.ZlibTail.rst
new file mode 100644
index 00000000000000..7c965451c056a4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-09-25-22-15-54.gh-issue-158169.ZlibTail.rst
@@ -0,0 +1,2 @@
+Fix :attr:`zlib.Decompress.unconsumed_tail` duplicating
+:attr:`~zlib.Decompress.unused_data` after end of stream when *max_length* was 
used.
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index a7fefb1fec5de9..39164ccee6a829 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -838,6 +838,7 @@ save_unconsumed_input(compobject *self, Py_buffer *data, 
int err)
                 return -1;
             }
             Py_SETREF(self->unused_data, new_unused_data);
+            self->zst.next_in += left_size;
             self->zst.avail_in = 0;
         }
     }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to