# CVE-2020-16845: Go encoding/binary infinite loop in ReadUvarint and ReadVarint

Source: https://junglewise.ai/threats/cve-2020-16845-go-encoding-binary-infinite-loop-in-readuvarint-and-readvarint  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2021-12-16. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2020-16845 · Severity: high · CVSS 7.5 · Published 2021-12-16

The Go standard library's encoding/binary package contains functions that can enter an infinite loop when processing specially crafted invalid input. This vulnerability allows a remote attacker to cause a denial of service by sending malicious data to applications that use these functions, consuming CPU resources indefinitely and making the service unavailable.

Technologies: [github.com/ulikunitz/xz (Go)](https://junglewise.ai/threats/technologies/github-com-ulikunitz-xz), [stdlib (Go)](https://junglewise.ai/threats/technologies/go-stdlib). Vendors: [Go](https://junglewise.ai/threats/vendors/go).

## Quick answers

**Is CVE-2020-16845 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2020-16845 being exploited in the wild.

**How severe is CVE-2020-16845?** High severity, with a CVSS score of 7.5, published 16 December 2021.

**Which products and versions are affected?** github.com/ulikunitz/xz (Go) < 0.5.8, SEMVER:introduced=0,fixed=0.5.8; stdlib (Go) SEMVER:introduced=0,fixed=1.13.15,introduced=1.14.0-0,fixed=1.14.7.

**Is there a fix for CVE-2020-16845?** Yes. github.com/ulikunitz/xz (Go): upgrade to 0.5.8 or later; stdlib (Go): upgrade to 1.14.7 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2020-16845 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2020-16845?** Check whether you run github.com/ulikunitz/xz (Go) or stdlib (Go) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- github.com/ulikunitz/xz (Go): upgrade to 0.5.8 or later

  ```sh
  go get github.com/ulikunitz/xz@v0.5.8
  ```

- stdlib (Go): upgrade to 1.14.7 or later

  ```sh
  go get stdlib@v1.14.7
  ```


## Technical details

This vulnerability is a denial-of-service issue in the encoding/binary package's ReadUvarint and ReadVarint functions. When processing variable-length integer encoded data, these functions can receive input bytes that lack a proper termination condition, causing the read loop to continue indefinitely. The vulnerability requires network-accessible input to the affected functions but no authentication or special privileges. An attacker can exploit this by sending malformed varint-encoded data to an application, causing CPU resource exhaustion and service unavailability. The fix, implemented in Go 1.13.15 and 1.14.7, adds a check to limit the number of bytes read (maximum 10 bytes for 64-bit varint) before returning an overflow error. The same vulnerability was independently discovered and fixed in the third-party ulikunitz/xz Go library (patched in version 0.5.8).

## Affected products

- Go Go standard library before 1.13.15 and 1.14.x before 1.14.7
- ulikunitz xz before 0.5.8

## Identifiers

- CVE-2020-16845
- GHSA-q6gq-997w-f55g
- GO-2021-0142

## Timeline

- 2020-08-06: disclosed: Vulnerability disclosed via NVD
- 2020-08: other: Vulnerability reported to ulikunitz/xz project
- 2020: patched: Go 1.13.15 and 1.14.7 released with fixes
- 2020: patched: ulikunitz/xz version 0.5.8 released with fix
- 2021-12-16: advisory: Published to GitHub Advisory Database
- 2025-10-14: other: Advisory withdrawn from GitHub because alerts cannot be issued for Go standard library

## References

- [https://github.com/ulikunitz/xz/issues/35](https://github.com/ulikunitz/xz/issues/35)
- [https://github.com/ulikunitz/xz/commit/69c6093c7b2397b923acf82cb378f55ab2652b9b](https://github.com/ulikunitz/xz/commit/69c6093c7b2397b923acf82cb378f55ab2652b9b)
- [https://groups.google.com/forum/](https://groups.google.com/forum/)
- [https://groups.google.com/forum/](https://groups.google.com/forum/)
- [https://lists.debian.org/debian-lts-announce/2020/11/msg00037.html](https://lists.debian.org/debian-lts-announce/2020/11/msg00037.html)

## Related threats

- [Go HTTP/1 server race condition in MaxBytesReader header handling](https://junglewise.ai/threats/cve-2026-97054-for-http-1-servers-when-maxbytesreader-s-limit-is-exceeded)
- [Go crypto/x509 untrusted intermediate certificate validation](https://junglewise.ai/threats/cve-2026-111943-on-most-platforms-go-uses-the-given-system-root-certificates)
- [Go crypto/tls malformed ECH extension DoS](https://junglewise.ai/threats/cve-2026-97031-go-2026-6607-reject-malformed-ech-outer-extension-references-in)
- [Go html/template XSS via missing ES2015+ keywords](https://junglewise.ai/threats/cve-2026-97030-go-2026-6600-recognize-yield-as-regexp-preceder-keyword-in-html)
- [Go html/template XSS via stale context in consecutive expressions](https://junglewise.ai/threats/cve-2026-94448-go-2026-6599-reset-context-tracking-on-consecutive-template)
