{"id":"CVE-2025-58058","aliases":["CVE-2025-58058","GHSA-jc7w-c686-c4v9","GO-2025-3922"],"related":["CGA-ph6j-9ffx-7pf8"],"kind":"vulnerability","state":"published","title":"github.com/ulikunitz/xz leaks memory when decoding a corrupted multiple LZMA archives","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"### Summary\n\nIt 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](https://github.com/jljusten/LZMA-SDK/blob/master/DOC/lzma-specification.txt).\n\nNote that the code recognizes the issue later while reading the stream, but at this time the memory allocation has already been done.\n\n### Mitigations\n\nThe release v0.5.15 includes following mitigations:\n\n- The ReaderConfig DictCap field is now interpreted as a limit for the dictionary size.\n- The default is 2 Gigabytes - 1 byte (2^31-1 bytes).\n- Users can check with the [Reader.Header] method what the actual values are in  their LZMA files and set a smaller limit using ReaderConfig.\n- 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.\n- The code supports stream sizes only up to a pebibyte (1024^5).\n\nNote that the original v0.5.14 version had a compiler error for 32 bit platforms, which has been fixed by v0.5.15.\n\n### Methods affected\n\nOnly software that uses [lzma.NewReader](https://pkg.go.dev/github.com/ulikunitz/xz/lzma#NewReader) or [lzma.ReaderConfig.NewReader](https://pkg.go.dev/github.com/ulikunitz/xz/lzma#ReaderConfig.NewReader) is affected. There is no issue for software using the xz functionality.\n\nI thank  @GregoryBuligin for his report, which is provided below.\n\n### Summary\nWhen 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.\n\n### Details\nJudging by the error  __writeMatch: distance out of range__, the problems occur in the code around this function.\nhttps://github.com/ulikunitz/xz/blob/c8314b8f21e9c5e25b52da07544cac14db277e89/lzma/decoderdict.go#L81\n\n### PoC\nRun 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.\n```\nconst ProjectLocalPath = \"some/path\"\nconst TmpDir = \"tmp\"\n\nfunc UnpackLZMA(lzmaFile string) error {\n\tfile, err := os.Open(lzmaFile)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\n\treader, err := lzma.NewReader(bufio.NewReader(file))\n\tif err != nil {\n\t\treturn err\n\t}\n\n\ttmpFile, err := os.CreateTemp(TmpDir, TmpLZMAPrefix)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer func() {\n\t\ttmpFile.Close()\n\t\t_ = os.Remove(tmpFile.Name())\n\t}()\n\n\tsha256Hasher := sha256.New()\n\tmultiWriter := io.MultiWriter(tmpFile, sha256Hasher)\n\n\tif _, err = io.Copy(multiWriter, reader); err != nil {\n\t\treturn err\n\t}\n\n\tunpackHash := hex.EncodeToString(sha256Hasher.Sum(nil))\n\tunpackDir := filepath.Join(\n\t\tProjectLocalPath, unpackHash[:2],\n\t)\n\t_ = os.MkdirAll(unpackDir, DirPerm)\n\n\tunpackPath := filepath.Join(unpackDir, unpackHash)\n\n\treturn os.Rename(tmpFile.Name(), unpackPath)\n}\n```\n\n\n\n### Impact\nServers with a small amount of RAM that download and unpack a large number of unverified LZMA archives","format":"markdown","source":"ghsa"},{"lang":"en","text":"Memory leaks when decoding a corrupted multiple LZMA archives in github.com/ulikunitz/xz","format":"markdown","source":"go"},{"lang":"es","text":"xz es un paquete puro de golang para leer y escribir archivos comprimidos xz. Antes de la versión 0.5.14, es posible colocar datos delante de un flujo de bytes codificado en LZMA sin detectar la situación al leer la cabecera. Esto puede llevar a un mayor consumo de memoria porque la implementación actual asigna el búfer de decodificación completo directamente después de leer la cabecera. La cabecera LZMA no incluye un número mágico ni tiene una suma de verificación para detectar tal problema según la especificación. Tenga en cuenta que el código reconoce el problema más tarde al leer el flujo, pero en este momento la asignación de memoria ya se ha realizado. Este problema ha sido parcheado en la versión 0.5.14.","source":"nvd"}],"published":"2025-08-28T19:36:22.000Z","modified":"2026-09-26T00:10:00.127Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L","score":5.3,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L","score":5.3,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L","score":5.3,"rating":"MEDIUM"}],"cwes":["CWE-770"],"affected":[{"ranges":[{"version":"< 0.5.14","status":"affected"}],"vendor":"ulikunitz","product":"xz","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.5.15"}],"ecosystem":"Go","package":"github.com/ulikunitz/xz","purl":"pkg:golang/github.com/ulikunitz/xz","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.5.15"}],"ecosystem":"Go","package":"github.com/ulikunitz/xz","purl":"pkg:golang/github.com/ulikunitz/xz","source":"go"}],"references":[{"url":"https://github.com/ulikunitz/xz/security/advisories/GHSA-jc7w-c686-c4v9","tags":["advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/ulikunitz/xz/commit/88ddf1d0d98d688db65de034f48960b2760d2ae2","tags":["fix","web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2025-58058","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/ulikunitz/xz","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2025-08-29T13:22:52.507Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2025-58058","url":"https://www.cve.org/CVERecord?id=CVE-2025-58058","licence":"CVE Terms of Use","modified":"2025-08-29T13:23:07.497Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-jc7w-c686-c4v9","url":"https://github.com/advisories/GHSA-jc7w-c686-c4v9","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:27.157Z"},{"source":"go","name":"Go Vulnerability Database","id":"GO-2025-3922","url":"https://pkg.go.dev/vuln/GO-2025-3922","licence":"CC-BY-4.0","modified":"2026-02-04T03:52:11.088Z"},{"source":"nvd","name":"NVD","id":"CVE-2025-58058","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-58058","licence":"Public domain","modified":"2026-09-26T00:10:00.127Z"}],"updatedAt":"2026-11-25T22:59:03.838Z","epss":{"score":0.00514,"percentile":0.45267,"date":"2026-12-01T12:00:22.000Z"}}