lzma: unbounded dictionary-size allocation is a memory DoS (zipfile, tarfile, lzma.decompress)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug: LZMA decompression accepts an attacker-controlled dictionary size with no bound, and liblzma allocates the full dictionary up front when a decompressor is created. A few bytes of input can therefore force a multi-gigabyte allocation (memory denial of service).
Attack surfaces (both reported by OSS-Fuzz, both public):
zipfilewith an LZMA-compressed member: the 5-byte LZMA properties header in the member data declares the dictionary. A 1088-byte zip whose member declares a ~2 GiB dictionary OOMs the process. https://issues.oss-fuzz.com/issues/495472861tarfile's compression-detection loop: a 13-byte input whose first byte is a valid LZMA-alone properties byte (0x66) and whose remaining bytes encode a ~4 GiB dictionary is tried as LZMA; liblzma allocates 4 GiB before failing. https://issues.oss-fuzz.com/issues/482161128
Also reachable directly: lzma.decompress() / LZMADecompressor(format=FORMAT_AUTO) on untrusted bytes, and LZMADecompressor(FORMAT_RAW, filters=[{"dict_size": ...}]).
Root cause: two gaps:
parse_filter_spec_lzma()accepts anydict_size(up to UINT32_MAX) for raw LZMA1/LZMA2 filter chains; liblzma allocates that dictionary at decompressor creation.LZMADecompressordefaultsmemlimittoUINT64_MAX, so the FORMAT_ALONE/FORMAT_AUTO paths (where the header is parsed inside liblzma) are also unbounded.
Proposed fix (PR to follow):
- Reject
dict_size > LZMA_DICT_SIZE_MAX(1.5 GiB, liblzma's own maximum) inparse_filter_spec_lzma()withLZMAError. - Default the decompressor
memlimittoLZMA_DICT_SIZE_MAXinstead ofUINT64_MAX(callers may still pass an explicitmemlimit).
No legitimate streams are affected: liblzma presets cap at 64 MiB dictionaries, and 1.5 GiB is liblzma's own maximum supported dictionary size.
Reported by OSS-Fuzz (ClusterFuzz). Reproducers attached to the issues above.
Linked PRs
- gh-155650
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit parse_filter_spec_lzma() und LZMADecompressor und überprüfen Sie anschließend die im Issue beschriebenen zipfile- und tarfile-Pfade. Verwenden Sie die verlinkten OSS-Fuzz-Reproducer, um zu verifizieren, dass übergroße Wörterbücher keine unbegrenzte Allokation mehr verursachen, während normale LZMA-Streams und das explizite memlimit-Verhalten intakt bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- security
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100