From 48e648370f903f9b4d9d36bf519ac94afc32fa07 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Wed, 25 Jan 2023 16:52:48 +0100 Subject: [PATCH 1/2] Ensure test_zlib.ZlibDecompressorTest actually runs, fix errors in ZlibDecompressor --- Lib/test/test_zlib.py | 9 +++++++-- Modules/zlibmodule.c | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index ae54f6c46891c6..3dac70eb12852c 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -944,13 +944,18 @@ def choose_lines(source, number, seed=None, generator=random): """ -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/Modules/zlibmodule.c b/Modules/zlibmodule.c index 1cdfd01320288b..e2f7dbaca87a9f 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -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; From e4b342b88e434feb4b802e19ac86601a22cbebc2 Mon Sep 17 00:00:00 2001 From: Ruben Vorderman Date: Thu, 26 Jan 2023 06:44:38 +0100 Subject: [PATCH 2/2] Add blurb for _ZlibDecompressor error fix --- .../next/Library/2023-01-26-06-44-35.gh-issue-101323.h8Hk11.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-01-26-06-44-35.gh-issue-101323.h8Hk11.rst 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 index 00000000000000..f8419e130dbcd7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-01-26-06-44-35.gh-issue-101323.h8Hk11.rst @@ -0,0 +1,2 @@ +Fix a bug where errors where not thrown by zlib._ZlibDecompressor if +encountered during decompressing.