]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.24] encoding/pem: make Decode complexity linear
authorRoland Shoemaker <bracewell@google.com>
Tue, 30 Sep 2025 18:16:56 +0000 (11:16 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 7 Oct 2025 18:00:57 +0000 (11:00 -0700)
commit74d4d836b91318a8764b94bc2b4b66ff599eb5f2
tree81b0d4f5358357ecc3f451e4c5d2edebfac01469
parent5c3d61c886f7ecfce9a6d6d3c97e6d5a8afb17d1
[release-branch.go1.24] encoding/pem: make Decode complexity linear

Because Decode scanned the input first for the first BEGIN line, and
then the first END line, the complexity of Decode is quadratic. If the
input contained a large number of BEGINs and then a single END right at
the end of the input, we would find the first BEGIN, and then scan the
entire input for the END, and fail to parse the block, so move onto the
next BEGIN, scan the entire input for the END, etc.

Instead, look for the first END in the input, and then the first BEGIN
that precedes the found END. We then process the bytes between the BEGIN
and END, and move onto the bytes after the END for further processing.
This gives us linear complexity.

Fixes CVE-2025-61723
For #75676
Fixes #75708

Change-Id: I813c4f63e78bca4054226c53e13865c781564ccf
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/2921
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/2986
Reviewed-on: https://go-review.googlesource.com/c/go/+/709842
TryBot-Bypass: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
src/encoding/pem/pem.go
src/encoding/pem/pem_test.go