CVE-2025-58058: Memory Leak in github.com/ulikunitz/xz Due to Corrupted LZMA Archives
Summary
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
- golang-github-ulikunitz-xz · Debian:11
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.
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.
No signup required · Results in about 60 seconds
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 →
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.
References
Related vulnerabilities
Recent vulnerabilities recorded for github.com/ulikunitz/xz.