]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101322: Ensure test_zlib.ZlibDecompressorTest runs, fix errors in ZlibDecompressor...
authorRuben Vorderman <r.h.p.vorderman@lumc.nl>
Sat, 4 Feb 2023 20:07:30 +0000 (21:07 +0100)
committerGitHub <noreply@github.com>
Sat, 4 Feb 2023 20:07:30 +0000 (12:07 -0800)
* Ensure test_zlib.ZlibDecompressorTest actually runs, fix errors in ZlibDecompressor.

Lib/test/test_zlib.py
Misc/NEWS.d/next/Library/2023-01-26-06-44-35.gh-issue-101323.h8Hk11.rst [new file with mode: 0644]
Modules/zlibmodule.c

index ae54f6c46891c6871cc7567e49f587dc851612e8..3dac70eb12852cd82fe032f51ea9f0014d92ccfc 100644 (file)
@@ -944,13 +944,18 @@ LAERTES
 """
 
 
-class ZlibDecompressorTest():
+class ZlibDecompressorTest(unittest.TestCase):
     # Test adopted from test_bz2.py
     TEXT = HAMLET_SCENE
     DATA = zlib.compress(HAMLET_SCENE)
     BAD_DATA = b"Not a valid deflate block"
+    BIG_TEXT = DATA * ((128 * 1024 // len(DATA)) + 1)
+    BIG_DATA = zlib.compress(BIG_TEXT)
+
     def test_Constructor(self):
-        self.assertRaises(TypeError, zlib._ZlibDecompressor, 42)
+        self.assertRaises(TypeError, zlib._ZlibDecompressor, "ASDA")
+        self.assertRaises(TypeError, zlib._ZlibDecompressor, -15, "notbytes")
+        self.assertRaises(TypeError, zlib._ZlibDecompressor, -15, b"bytes", 5)
 
     def testDecompress(self):
         zlibd = zlib._ZlibDecompressor()
diff --git a/Misc/NEWS.d/next/Library/2023-01-26-06-44-35.gh-issue-101323.h8Hk11.rst b/Misc/NEWS.d/next/Library/2023-01-26-06-44-35.gh-issue-101323.h8Hk11.rst
new file mode 100644 (file)
index 0000000..f8419e1
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a bug where errors where not thrown by zlib._ZlibDecompressor if
+encountered during decompressing.
index 1cdfd01320288b38260ca325683ac5d484348442..e2f7dbaca87a9f7ab9231006b885f2ba3ad34fc1 100644 (file)
@@ -1519,6 +1519,7 @@ decompress_buf(ZlibDecompressor *self, Py_ssize_t max_length)
         }
     } else if (err != Z_OK && err != Z_BUF_ERROR) {
         zlib_error(state, self->zst, err, "while decompressing data");
+        goto error;
     }
 
     self->avail_in_real += self->zst.avail_in;