Skip to content

Commit 55c9239

Browse files
committed
Issue #28275: Merge bz2 fix from 3.5 into 3.6
2 parents ef223a1 + 38317d3 commit 55c9239

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

Lib/test/test_bz2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,12 @@ def test_decompressor_inputbuf_3(self):
821821
out.append(bzd.decompress(self.DATA[300:]))
822822
self.assertEqual(b''.join(out), self.TEXT)
823823

824+
def test_failure(self):
825+
bzd = BZ2Decompressor()
826+
self.assertRaises(Exception, bzd.decompress, self.BAD_DATA * 30)
827+
# Previously, a second call could crash due to internal inconsistency
828+
self.assertRaises(Exception, bzd.decompress, self.BAD_DATA * 30)
829+
824830
class CompressDecompressTest(BaseTest):
825831
def testCompress(self):
826832
data = bz2.compress(self.TEXT)

Lib/test/test_lzma.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,9 @@ def test_decompressor_bad_input(self):
249249
def test_decompressor_bug_28275(self):
250250
# Test coverage for Issue 28275
251251
lzd = LZMADecompressor()
252-
for i in range(2):
253-
try:
254-
lzd.decompress(COMPRESSED_RAW_1)
255-
except LZMAError:
256-
pass
252+
self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_RAW_1)
253+
# Previously, a second call could crash due to internal inconsistency
254+
self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_RAW_1)
257255

258256
# Test that LZMACompressor->LZMADecompressor preserves the input data.
259257

Misc/NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ Library
6767
that they don't call itermonthdates() which can cause datetime.date
6868
under/overflow.
6969

70-
- Issue #28275: Fixed possible use adter free in LZMADecompressor.decompress().
70+
- Issue #28275: Fixed possible use after free in the decompress()
71+
methods of the LZMADecompressor and BZ2Decompressor classes.
7172
Original patch by John Leitch.
7273

7374
- Issue #27897: Fixed possible crash in sqlite3.Connection.create_collation()

Modules/_bz2module.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,10 @@ decompress(BZ2Decompressor *d, char *data, size_t len, Py_ssize_t max_length)
534534
}
535535

536536
result = decompress_buf(d, max_length);
537-
if(result == NULL)
537+
if(result == NULL) {
538+
bzs->next_in = NULL;
538539
return NULL;
540+
}
539541

540542
if (d->eof) {
541543
d->needs_input = 0;

0 commit comments

Comments
 (0)