GeezerVison is showing github.com — gh-155649: Bound LZMA dictionary size to prevent memory DoS by DeseretSaint · Pull Request #155650 · python/cpython
Conversation
DeseretSaint
commented
Aug 13, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
liblzma allocates the full LZMA dictionary up front when a decompressor is created, and the dictionary size comes from the stream header. An untrusted stream can declare a multi-gigabyte dictionary (up to 4 GiB) and force that allocation from a handful of bytes — a memory denial of service.
Both crash paths were reported by OSS-Fuzz (python3-libraries, public):
Directly reachable too: lzma.decompress() / LZMADecompressor(FORMAT_AUTO) on untrusted bytes, and LZMADecompressor(FORMAT_RAW, filters=[{"dict_size": ...}]).
Changes
parse_filter_spec_lzma() rejects dict_size above liblzma's own maximum (LZMA_DICT_SIZE_MAX, 1.5 GiB) with LZMAError — covers raw LZMA1/LZMA2 filter chains, including zipfile's LZMA members (the dictionary is parsed from the 5-byte properties header before any data is decompressed).
LZMADecompressor defaults memlimit to LZMA_DICT_SIZE_MAX instead of UINT64_MAX — bounds the FORMAT_AUTO/FORMAT_ALONE/FORMAT_XZ paths where the header is parsed inside liblzma (tarfile compression detection, lzma.decompress(), LZMAFile).
An explicit memlimit can still be passed to raise or lower the bound.
Compatibility: liblzma presets cap at 64 MiB dictionaries; 1.5 GiB is liblzma's own maximum supported dictionary size, so no legitimate stream is affected.
Tests: new regression tests in test_lzma.py, test_zipfile (crafted bomb zip → LZMAError), and test_tarfile (13-byte fake-LZMA input → ReadError). test_lzma test_zipfile test_tarfile all pass (1,487 tests).
Companion fuzzer-harness change: https://github.com/python/library-fuzzers/pull/… (zipfile fuzzer now tolerates lzma.LZMAError).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
liblzma allocates the full LZMA dictionary up front when a decompressor
is created, and the dictionary size comes from the stream header. An
untrusted stream could declare a multi-gigabyte dictionary (up to 4 GiB)
and force that allocation from a handful of bytes, exhausting memory.
Two gaps are closed:
- parse_filter_spec_lzma() now rejects dict_size above liblzma's own
maximum (LZMA_DICT_SIZE_MAX, 1.5 GiB) with LZMAError. This covers
raw LZMA1/LZMA2 filter chains, including zipfile's LZMA members.
- LZMADecompressor now defaults memlimit to LZMA_DICT_SIZE_MAX instead
of UINT64_MAX, bounding the FORMAT_AUTO/FORMAT_ALONE/FORMAT_XZ paths
(e.g. tarfile's compression detection and lzma.decompress()).
An explicit memlimit can still be passed to adjust the bound.
Fixes OSS-Fuzz reports (python3-libraries):
- fuzzer-zipfile OOM: https://issues.oss-fuzz.com/issues/495472861
- fuzzer-tarfile OOM: https://issues.oss-fuzz.com/issues/482161128
|
All commit authors signed the Contributor License Agreement.

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLA check is failing, kindly sign the CLA so that maintainers can start review process.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 90 days with no activity.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
ethanfurman
Awaiting requested review from ethanfurman
ethanfurman is a code owner
1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|