CVE-2020-16845 Overview
CVE-2020-16845 is a denial of service vulnerability affecting the Go programming language runtime. The flaw exists in the encoding/binary package, specifically in the ReadUvarint and ReadVarint functions, which can enter an infinite read loop when processing specially crafted invalid inputs. This vulnerability allows remote attackers to cause resource exhaustion and denial of service conditions in applications that process untrusted binary data using these functions.
Critical Impact
Applications using Go's encoding/binary package to parse untrusted input are vulnerable to denial of service attacks through infinite loop conditions, potentially causing complete service unavailability.
Affected Products
- Golang Go versions before 1.13.15
- Golang Go 1.14.x versions before 1.14.7
- openSUSE Leap 15.1 and 15.2
- Debian Linux 9.0 and 10.0
- Fedora 31 and 32
Discovery Timeline
- August 6, 2020 - CVE-2020-16845 published to NVD
- November 21, 2024 - Last updated in NVD database
Technical Details for CVE-2020-16845
Vulnerability Analysis
The vulnerability resides in the Go standard library's encoding/binary package, which provides functions for reading and writing binary data. The ReadUvarint and ReadVarint functions are designed to read variable-length integers from an io.ByteReader interface. These functions implement a loop that continues reading bytes until a termination condition is met, specifically when a byte with its most significant bit (MSB) unset is encountered.
The root cause is insufficient validation of input data during the variable-length integer decoding process. When malformed input is provided—specifically input that never satisfies the termination condition—the functions enter an infinite loop, continuously attempting to read additional bytes. This behavior causes the affected goroutine to consume CPU resources indefinitely, leading to denial of service.
Variable-length integers (varints) are commonly used in protocol buffers, binary serialization formats, and network protocols. Any Go application that uses binary.ReadUvarint() or binary.ReadVarint() to parse data from untrusted sources is potentially vulnerable to this attack.
Root Cause
The vulnerability is classified under CWE-835 (Loop with Unreachable Exit Condition). The ReadUvarint and ReadVarint functions lack proper bounds checking on the number of bytes read during variable-length integer decoding. When processing a maliciously crafted byte sequence where every byte has its continuation bit set (MSB = 1), the loop never reaches its exit condition, resulting in infinite execution.
Attack Vector
An attacker can exploit this vulnerability remotely by sending specially crafted binary data to any Go application that processes variable-length integers from untrusted input. The attack requires network access to the vulnerable application and involves sending a sequence of bytes where each byte has the most significant bit set, preventing the loop from terminating. This is particularly impactful for services that:
- Process Protocol Buffers or similar serialization formats
- Handle binary network protocols
- Parse user-uploaded binary files
- Implement custom binary data formats
The exploitation is straightforward, requiring only the ability to send malformed binary data to the target application. No authentication or special privileges are required, making this a significant concern for internet-facing services built with vulnerable Go versions.
Detection Methods for CVE-2020-16845
Indicators of Compromise
- Abnormally high CPU utilization in Go-based services without corresponding increase in legitimate traffic
- Goroutines stuck in extended execution states within encoding/binary package functions
- Memory patterns showing repeated read operations on the same input stream
- Service degradation or timeouts in applications processing binary data
Detection Strategies
- Monitor Go application CPU usage patterns for sustained spikes that correlate with binary data processing
- Implement application-level logging for encoding/binary function calls with timing metrics
- Deploy runtime monitoring to detect goroutines that exceed expected execution thresholds
- Use Go's built-in profiling tools (pprof) to identify infinite loop patterns in production
Monitoring Recommendations
- Configure alerts for sustained CPU utilization above baseline thresholds in Go services
- Implement request timeout enforcement at the application and infrastructure levels
- Monitor goroutine counts and execution times using observability tooling
- Review application logs for patterns indicating repeated parsing failures on binary input
How to Mitigate CVE-2020-16845
Immediate Actions Required
- Upgrade Go runtime to version 1.13.15 or later for 1.13.x branch
- Upgrade Go runtime to version 1.14.7 or later for 1.14.x branch
- Recompile all Go applications with the patched Go runtime versions
- Implement input validation and size limits for binary data processing
- Deploy request timeouts and circuit breakers for services handling binary input
Patch Information
The Go team addressed this vulnerability in Go versions 1.13.15 and 1.14.7, released in August 2020. The fix adds proper bounds checking to the ReadUvarint and ReadVarint functions to prevent infinite loop conditions. Organizations should update their Go toolchain and recompile all affected applications.
Security advisories and patches have been issued by multiple distribution maintainers:
Workarounds
- Implement input size limits and validation before passing data to ReadUvarint or ReadVarint
- Use custom wrapper functions that enforce maximum byte counts during varint decoding
- Deploy request timeouts at the HTTP/network layer to terminate long-running operations
- Consider using alternative parsing libraries with built-in bounds checking until patching is complete
# Check current Go version
go version
# Upgrade Go to patched version (example for Linux)
# Download Go 1.14.7 or later from https://golang.org/dl/
wget https://golang.org/dl/go1.14.7.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.14.7.linux-amd64.tar.gz
# Rebuild affected applications
cd /path/to/your/app
go build -a
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

