CVE-2022-24675: Stack overflow in encoding/pem package
Summary
CVE-2022-24675: Stack overflow from a large amount of PEM data in encoding/pem. Affects stdlib across 2 version ranges.
< 1.17.9
>= 1.18.0-0, < 1.18.1
Fixed in 1.17.9 or 1.18.1, depending on the release line you run. How to fix ↓
Also tracked for
- golang · Bitnami
The same CVE-2022-24675 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 encoding/pem package is a part of the Go standard library (stdlib) and provides functions for encoding and decoding PEM data. PEM (Privacy Enhanced Mail) is a format for storing and transmitting cryptographic keys, certificates, and other sensitive data. The encoding/pem package is widely used in Go applications for handling PEM data.
Vulnerability Detail
The encoding/pem package in Go before version 1.17.9 and 1.18.x before 1.18.1 is vulnerable to a stack overflow when processing a large amount of PEM data. This vulnerability can be exploited by an attacker to cause a denial-of-service (DoS) condition or potentially execute arbitrary code. The issue arises due to improper handling of the input data, leading to a stack overflow.
How To Fix
Latest published version: go1.25.5 as of 22 Oct 2026
go get stdlib@vgo1.25.5
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 1.17.91.17.9go get stdlib@v1.17.9 -
>= 1.18.0-0, < 1.18.11.18.1go get stdlib@v1.18.1
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a temporary workaround, developers can limit the size of the PEM data being processed by the encoding/pem package. By validating and restricting the input data size, the risk of triggering the stack overflow can be mitigated. Here is an example of how to limit the size of PEM data in Go:
import (
"encoding/pem"
"io"
"io/ioutil"
)
func processPEMData(data []byte) error {
const maxPEMSize = 1024 * 1024 // 1MB
if len(data) > maxPEMSize {
return fmt.Errorf("PEM data size exceeds the maximum allowed limit")
}
// Process the PEM data
// ...
return nil
}
Conclusion
In conclusion, the encoding/pem package in Go versions before 1.17.9 and 1.18.x before 1.18.1 is vulnerable to a stack overflow issue. This vulnerability can be mitigated by updating the Go installation to the patched versions or by applying a temporary workaround to limit the size of the processed PEM data. It is recommended to take immediate action to address this vulnerability and prevent any potential security breaches. For further support and assistance in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for stdlib →
FAQ
This vulnerability can lead to a denial-of-service (DoS) condition or potential remote code execution if exploited by an attacker. It is important to update the affected Go installations to prevent any potential security breaches.
You can use the Vulert Playground at Vulert Scanner to check if your application is affected by this vulnerability. The Vulert Playground allows you to analyze your Gopkg.lock file and provides real-time alerts for open-source vulnerabilities in your software.
At the time of this report, there are no known instances of this vulnerability being actively exploited. However, it is crucial to update the affected Go installations as a proactive measure to mitigate any potential risks.
While updating Go to the patched versions is the recommended solution, you can apply a temporary workaround by limiting the size of the PEM data being processed by the encoding/pem package. This can help mitigate the risk of triggering the stack overflow. Please refer to the 'workaround' section for more details.
You can find more information about this vulnerability, including technical details and the affected versions, in the Go vulnerability database at https://pkg.go.dev/vuln/GO-2022-0433.
References
Related vulnerabilities
Recent vulnerabilities recorded for stdlib.