gh-101322: Ensure test_zlib.ZlibDecompressorTest runs, fix errors in ZlibDecompressor (#101323)

* Ensure test_zlib.ZlibDecompressorTest actually runs, fix errors in ZlibDecompressor.
This commit is contained in:
Ruben Vorderman 2023-02-04 21:07:30 +01:00 committed by GitHub
parent 144aaa74bb
commit a89e6713c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View file

@ -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()

View file

@ -0,0 +1,2 @@
Fix a bug where errors where not thrown by zlib._ZlibDecompressor if
encountered during decompressing.

View 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;