diff options
author | Ruben Vorderman <r.h.p.vorderman@lumc.nl> | 2023-02-04 20:07:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-04 20:07:30 (GMT) |
commit | a89e6713c4de99d4be5a1304b134e57a24ab10ac (patch) | |
tree | 5859cc6495c07c995c65694d41a9c60f3ac71611 | |
parent | 144aaa74bbd77aee822ee92344744dbb05aa2f30 (diff) | |
download | cpython-a89e6713c4de99d4be5a1304b134e57a24ab10ac.zip cpython-a89e6713c4de99d4be5a1304b134e57a24ab10ac.tar.gz cpython-a89e6713c4de99d4be5a1304b134e57a24ab10ac.tar.bz2 |
gh-101322: Ensure test_zlib.ZlibDecompressorTest runs, fix errors in ZlibDecompressor (#101323)
* Ensure test_zlib.ZlibDecompressorTest actually runs, fix errors in ZlibDecompressor.
-rw-r--r-- | Lib/test/test_zlib.py | 9 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-01-26-06-44-35.gh-issue-101323.h8Hk11.rst | 2 | ||||
-rw-r--r-- | Modules/zlibmodule.c | 1 |
3 files changed, 10 insertions, 2 deletions
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index ae54f6c..3dac70e 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -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 index 0000000..f8419e1 --- /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. diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 1cdfd01..e2f7dba 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; |