]> Cypherpunks repositories - gostls13.git/commit
encoding/asn1: prevent memory exhaustion when parsing using internal/saferio
authorNicholas Husin <husin@google.com>
Wed, 3 Sep 2025 13:30:56 +0000 (09:30 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 7 Oct 2025 18:23:23 +0000 (11:23 -0700)
commit8709a41d5ef7321f486a1857f189c3fee20e8edd
tree0d5610befec3c30413825f1a114cb844ac168e3a
parent9b9d02c5a015910ce57024788de2ff254c6cfca6
encoding/asn1: prevent memory exhaustion when parsing using internal/saferio

Within parseSequenceOf, reflect.MakeSlice is being used to pre-allocate
a slice that is needed in order to fully validate the given DER payload.
The size of the slice allocated are also multiple times larger than the
input DER:

- When using asn1.Unmarshal directly, the allocated slice is ~28x
  larger.
- When passing in DER using x509.ParseCertificateRequest, the allocated
  slice is ~48x larger.
- When passing in DER using ocsp.ParseResponse, the allocated slice is
  ~137x larger.

As a result, a malicious actor can craft a big empty DER payload,
resulting in an unnecessary large allocation of memories. This can be a
way to cause memory exhaustion.

To prevent this, we now use SliceCapWithSize within internal/saferio to
enforce a memory allocation cap.

Thanks to Jakub Ciolek for reporting this issue.

For #75671
Fixes CVE-2025-58185

Change-Id: Id50e76187eda43f594be75e516b9ca1d2ae6f428
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/2700
Reviewed-by: Roland Shoemaker <bracewell@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/709856
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
src/encoding/asn1/asn1.go
src/encoding/asn1/asn1_test.go
src/go/build/deps_test.go