diff --git a/src/core/IronPython.Modules/zlib/zlib.net/InfTree.cs b/src/core/IronPython.Modules/zlib/zlib.net/InfTree.cs index 3a0be26d6..f0c21f56a 100644 --- a/src/core/IronPython.Modules/zlib/zlib.net/InfTree.cs +++ b/src/core/IronPython.Modules/zlib/zlib.net/InfTree.cs @@ -312,7 +312,7 @@ internal static int inflate_trees_bits(int[] c, int[] bb, int[] tb, int[] hp, ZS { z.msg = "oversubscribed dynamic bit lengths tree"; } - else if (r == (int)ZLibResultCode.Z_DATA_ERROR || bb[0] == 0) + else if (r == (int)ZLibResultCode.Z_BUF_ERROR || bb[0] == 0) { z.msg = "incomplete dynamic bit lengths tree"; r = (int)ZLibResultCode.Z_DATA_ERROR; diff --git a/tests/suite/modules/misc/test_zlib.py b/tests/suite/modules/misc/test_zlib.py index 0a063537e..fcb928fc5 100644 --- a/tests/suite/modules/misc/test_zlib.py +++ b/tests/suite/modules/misc/test_zlib.py @@ -76,6 +76,16 @@ def test_deflate(self): self.assertEqual(do.decompress(self.deflate_data), self.text) self.assertEqual(zlib.decompress(self.deflate_data, -zlib.MAX_WBITS), self.text) + def test_invalid_bit_length_trees(self): + # These dynamic blocks have incomplete and oversubscribed code-length alphabets. + for data in (b'\x05\x00\x00\x01', b'\x05\x00\x92\x00'): + with self.subTest(data=data, api='decompress'): + with self.assertRaisesRegex(zlib.error, r'Error -3\b'): + zlib.decompress(data, -zlib.MAX_WBITS) + with self.subTest(data=data, api='decompressobj'): + with self.assertRaisesRegex(zlib.error, r'Error -3\b'): + zlib.decompressobj(-zlib.MAX_WBITS).decompress(data) + def test_gzip_stream(self): """gzip header, uncomplete header""" for delta in range(1, 25):