Skip to content

Commit 0154405

Browse files
authored
gh-104282: Fix null pointer dereference in lzma._decode_filter_properties (GH-104283)
1 parent b204c4b commit 0154405

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
@@ -492,7 +492,9 @@ build_filter_spec(const lzma_filter *f)
492492
case LZMA_FILTER_ARMTHUMB:
493493
case LZMA_FILTER_SPARC: {
494494
lzma_options_bcj *options = f->options;
495-
ADD_FIELD(options, start_offset);
495+
if (options) {
496+
ADD_FIELD(options, start_offset);
497+
}
496498
break;
497499
}
498500
default:

0 commit comments

Comments
 (0)