aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
authorRoland Shoemaker <roland@golang.org>2025-10-23 08:16:39 -0700
committerGopher Robot <gobot@golang.org>2025-10-23 08:52:44 -0700
commit839da71f8907ac4434299db4353db31835c916df (patch)
tree0e495a6a2d05890044eeeb8799b1a1127a3cee1c /src/encoding
parent39ed968832ad8923a4bd1fb6bc3d9090ddd98401 (diff)
downloadgo-839da71f8907ac4434299db4353db31835c916df.tar.xz
encoding/pem: properly calculate end indexes
When a block is missing the END line trailer, calculate the indexes of the end and end trailer _before_ continuing the loop, making the reslicing at the start of the loop work as expected. Change-Id: If45c8cb473315623618f02cc7609f517a72d232d Reviewed-on: https://go-review.googlesource.com/c/go/+/714200 Auto-Submit: Roland Shoemaker <roland@golang.org> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/pem/pem.go4
-rw-r--r--src/encoding/pem/pem_test.go4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/encoding/pem/pem.go b/src/encoding/pem/pem.go
index 2356096ade..1da60d3227 100644
--- a/src/encoding/pem/pem.go
+++ b/src/encoding/pem/pem.go
@@ -116,11 +116,11 @@ func Decode(data []byte) (p *Block, rest []byte) {
var typeLine []byte
var consumed int
typeLine, rest, consumed = getLine(rest)
+ endIndex -= consumed
+ endTrailerIndex -= consumed
if !bytes.HasSuffix(typeLine, pemEndOfLine) {
continue
}
- endIndex -= consumed
- endTrailerIndex -= consumed
typeLine = typeLine[0 : len(typeLine)-len(pemEndOfLine)]
p = &Block{
diff --git a/src/encoding/pem/pem_test.go b/src/encoding/pem/pem_test.go
index 5bdc2f66a7..fa6e8ba62b 100644
--- a/src/encoding/pem/pem_test.go
+++ b/src/encoding/pem/pem_test.go
@@ -736,3 +736,7 @@ func FuzzDecode(f *testing.F) {
Decode(data)
})
}
+
+func TestMissingEndTrailer(t *testing.T) {
+ Decode([]byte{0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xa, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20})
+}