CVE-2025-58058: github.com/ulikunitz/xz leaks memory when decoding a corrupted multiple LZMA archives
5.3
Basic Information
Technical Details
| Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
|---|---|---|---|
| github.com/ulikunitz/xz | go | <= 0.5.13 | 0.5.14 |
Vulnerability Intelligence
Miggo AI
Root Cause Analysis
The vulnerability is a memory exhaustion issue in the github.com/ulikunitz/xz library's LZMA decoder, identified as GHSA-jc7w-c686-c4v9. The root cause is insufficient validation of the dictionary size read from an LZMA stream's header. The LZMA file format lacks a magic number, making it difficult to detect if the stream is valid or has been prepended with extraneous data.
An attacker can exploit this by prepending data, such as a single null byte, to a valid LZMA stream. When the library attempts to parse this corrupted stream, the lzma.Header.unmarshalBinary function reads an extremely large value for the dictionary size from the header.
Prior to the patch, the lzma.ReaderConfig.NewReader function would take this value and use it to allocate a dictionary buffer without imposing a reasonable upper limit. This would lead to an attempt to allocate a massive amount of memory, causing a denial-of-service (DoS) condition as the system's memory is exhausted.
The main vulnerable functions are lzma.NewReader (a wrapper) and lzma.ReaderConfig.NewReader (the core implementation), as they contain the flawed logic that fails to prevent the oversized memory allocation. The patch addresses this by treating the ReaderConfig.DictCap field as a strict upper limit for the dictionary size, adding a default limit of 2GB, and also capping the allocation size based on the uncompressed file size if it is known.