CVE-2025-58058: github.com/ulikunitz/xz leaks memory when decoding a corrupted multiple LZMA archives

Published Aug 28, 2025
·
Updated

Summary

It is possible to put data in front of an LZMA-encoded byte stream without detecting the situation while reading the header. This can lead to increased memory consumption because the current implementation allocates the full decoding buffer directly after reading the header. The LZMA header doesn't include a magic number or has a checksum to detect such an issue according to the specification.

Note that the code recognizes the issue later while reading the stream, but at this time the memory allocation has already been done.

Mitigations

The release v0.5.15 includes following mitigations:

- The ReaderConfig DictCap field is now interpreted as a limit for the dictionary size. - The default is 2 Gigabytes - 1 byte (2^31-1 bytes). - Users can check with the [Reader.Header] method what the actual values are in their LZMA files and set a smaller limit using ReaderConfig. - The dictionary size will not exceed the larger of the file size and the minimum dictionary size. This is another measure to prevent huge memory allocations for the dictionary. - The code supports stream sizes only up to a pebibyte (1024^5).

Note that the original v0.5.14 version had a compiler error for 32 bit platforms, which has been fixed by v0.5.15.

Methods affected

Only software that uses lzma.NewReader or lzma.ReaderConfig.NewReader is affected. There is no issue for software using the xz functionality.

I thank @GregoryBuligin for his report, which is provided below.

Summary When unpacking a large number of LZMA archives, even in a single goroutine, if the first byte of the archive file is 0 (a zero byte added to the beginning), an error writeMatch: distance out of range occurs. Memory consumption spikes sharply, and the GC clearly cannot handle this situation.

Details Judging by the error writeMatch: distance out of range, the problems occur in the code around this function. https://github.com/ulikunitz/xz/blob/c8314b8f21e9c5e25b52da07544cac14db277e89/lzma/decoderdict.go#L81

PoC Run a function similar to this one in 1 or several goroutines on a multitude of LZMA archives that have a 0 (a zero byte) added to the beginning. const ProjectLocalPath = "some/path" const TmpDir = "tmp"

func UnpackLZMA(lzmaFile string) error { file, err := os.Open(lzmaFile) if err != nil { return err } defer file.Close()

reader, err := lzma.NewReader(bufio.NewReader(file)) if err != nil { return err }

tmpFile, err := os.CreateTemp(TmpDir, TmpLZMAPrefix) if err != nil { return err } defer func() { tmpFile.Close() = os.Remove(tmpFile.Name()) }()

sha256Hasher := sha256.New() multiWriter := io.MultiWriter(tmpFile, sha256Hasher)

if , err = io.Copy(multiWriter, reader); err != nil { return err }

unpackHash := hex.EncodeToString(sha256Hasher.Sum(nil)) unpackDir := filepath.Join( ProjectLocalPath, unpackHash[:2], ) = os.MkdirAll(unpackDir, DirPerm)

unpackPath := filepath.Join(unpackDir, unpackHash)

return os.Rename(tmpFile.Name(), unpackPath) }

Impact Servers with a small amount of RAM that download and unpack a large number of unverified LZMA archives

Other sources

xz is a pure golang package for reading and writing xz-compressed files. Prior to version 0.5.14, it is possible to put data in front of an LZMA-encoded byte stream without detecting the situation while reading the header. This can lead to increased memory consumption because the current implementation allocates the full decoding buffer directly after reading the header. The LZMA header doesn't include a magic number or has a checksum to detect such an issue according to the specification. Note that the code recognizes the issue later while reading the stream, but at this time the memory allocation has already been done. This issue has been patched in version 0.5.14.

MITRE

Affected Software

2 affected componentsFixes available
go/github.com/ulikunitz/xz<=0.5.13
0.5.15
IBM Concert Software<=1.0.0-2.2.0

Event History

Aug 28, 2025
Advisory Published
via GitHub·07:36 PM
Data Sourced
via GitHub·07:36 PM
DescriptionSeverityWeaknessAffected Software
CVE Published
via MITRE·09:54 PM
Data Sourced
via MITRE·09:54 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·10:15 PM
DescriptionSeverityWeakness
Mar 23, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2025-58058?

CVE-2025-58058 is classified as a moderate severity vulnerability due to potential memory consumption issues.

2

How do I fix CVE-2025-58058?

To fix CVE-2025-58058, upgrade to version 0.5.14 or later of the affected package from github.com/ulikunitz/xz.

3

What software is affected by CVE-2025-58058?

CVE-2025-58058 affects versions up to and including 0.5.13 of the github.com/ulikunitz/xz package.

4

What kind of issue does CVE-2025-58058 present?

CVE-2025-58058 presents an issue where extra data can be added in front of an LZMA-encoded byte stream leading to unexpected memory allocation.

5

Is there a real-world exploit for CVE-2025-58058?

As of now, there are no known public exploits for CVE-2025-58058, but it is advisable to patch the vulnerability to prevent potential attacks.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203