Skip to content

Commit 00e7793

Browse files
[3.12] gh-104282: Fix null pointer dereference in lzma._decode_filter_properties (GH-104283) (GH-114181)
(cherry picked from commit 0154405) Co-authored-by: Radislav Chugunov <[email protected]>
1 parent 27941b1 commit 00e7793

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Lib/test/test_lzma.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,14 @@ def test__decode_filter_properties(self):
14011401
self.assertEqual(filterspec["lc"], 3)
14021402
self.assertEqual(filterspec["dict_size"], 8 << 20)
14031403

1404+
# see gh-104282
1405+
filters = [lzma.FILTER_X86, lzma.FILTER_POWERPC,
1406+
lzma.FILTER_IA64, lzma.FILTER_ARM,
1407+
lzma.FILTER_ARMTHUMB, lzma.FILTER_SPARC]
1408+
for f in filters:
1409+
filterspec = lzma._decode_filter_properties(f, b"")
1410+
self.assertEqual(filterspec, {"id": f})
1411+
14041412
def test_filter_properties_roundtrip(self):
14051413
spec1 = lzma._decode_filter_properties(
14061414
lzma.FILTER_LZMA1, b"]\x00\x00\x80\x00")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix null pointer dereference in :func:`lzma._decode_filter_properties`
2+
due to improper handling of BCJ filters with properties of zero length.
3+
Patch by Radislav Chugunov.

Modules/_lzmamodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,9 @@ build_filter_spec(const lzma_filter *f)
494494
case LZMA_FILTER_ARMTHUMB:
495495
case LZMA_FILTER_SPARC: {
496496
lzma_options_bcj *options = f->options;
497-
ADD_FIELD(options, start_offset);
497+
if (options) {
498+
ADD_FIELD(options, start_offset);
499+
}
498500
break;
499501
}
500502
default:

0 commit comments

Comments
 (0)