CVE-2025-58058: Memory Leak in github.com/ulikunitz/xz Due to Corrupted LZMA Archives

github.com/ulikunitz/xz Updated 02 Oct 2025

Summary

28/08/2025
Yes i
Moderate
5.3

CVE-2025-58058: github.com/ulikunitz/xz leaks memory when decoding a corrupted multiple LZMA archives. Affects github.com/ulikunitz/xz versions < 0.5.15. Fixed in 0.5.15. How to fix ↓

Also tracked for

The same CVE-2025-58058 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

Background

The package github.com/ulikunitz/xz is a Go library that provides functionality for reading and writing xz-compressed files, specifically using the LZMA compression algorithm. It is widely used in applications that require efficient data compression and decompression. However, a vulnerability has been identified in versions up to 0.5.13, where the library can leak memory when decoding corrupted LZMA archives, potentially leading to performance issues or application crashes.

Vulnerability Detail

The vulnerability arises from the inability of the library to detect data corruption in LZMA-encoded byte streams before allocating memory for decoding. Specifically, if a zero byte is added to the beginning of an LZMA archive, it can trigger a memory spike and an error during the decoding process. This occurs because the library allocates the full decoding buffer immediately after reading the header, without validating the integrity of the data. The lack of a magic number or checksum in the LZMA header exacerbates this issue, allowing corrupted data to go undetected until it is too late.

How To Fix

Latest published version: v0.5.17 as of 22 Oct 2026

go get github.com/ulikunitz/xz@v0.5.17

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

0.5.15

This is the first release that contains the fix.

go get github.com/ulikunitz/xz@v0.5.15

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If you cannot update to the patched version immediately, consider implementing a check before decoding LZMA archives to ensure that the input data is valid. Here is a sample code snippet that demonstrates how to handle LZMA decoding safely:

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)
}

Conclusion

The vulnerability CVE-2025-58058 in the github.com/ulikunitz/xz package poses a risk of memory leaks when handling corrupted LZMA archives. It is crucial to update to version 0.5.15 or later to mitigate this issue. Implementing proper checks and using tools like Vulert can help in managing and monitoring vulnerabilities effectively.

See every vulnerability recorded for github.com/ulikunitz/xz →

Share this vulnerability

FAQ

CVE-2025-58058 is a vulnerability in the github.com/ulikunitz/xz package that can lead to memory leaks when decoding corrupted LZMA archives.

If your application uses the affected version of the library, it may experience increased memory consumption or crashes when processing corrupted LZMA files.

Versions of the github.com/ulikunitz/xz package up to and including 0.5.13 are affected by this vulnerability.

You can use Vulert to monitor and alert for open-source vulnerabilities in your software. Visit Vulert Scanner to check if your application is affected without needing to sign up.

The CVSS score of this vulnerability is 5.3, indicating a moderate severity level.

Related vulnerabilities

Recent vulnerabilities recorded for github.com/ulikunitz/xz.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

How To Fix

Latest published version: v0.5.17 as of 22 Oct 2026

go get github.com/ulikunitz/xz@v0.5.17

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

0.5.15

This is the first release that contains the fix.

go get github.com/ulikunitz/xz@v0.5.15

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback