Skip to content

Commit 9f6590f

Browse files
rolandshoemakergopherbot
authored andcommitted
encoding/pem: don't reslice in failure modes
We re-slice the data being processed at the stat of each loop. If the var that we use to calculate where to re-slice is < 0 or > the length of the remaining data, return instead of attempting to re-slice. Change-Id: I1d6c2b6c596feedeea8feeaace370ea73ba02c4c Reviewed-on: https://go-review.googlesource.com/c/go/+/715260 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Roland Shoemaker <roland@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
1 parent 34fec51 commit 9f6590f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/encoding/pem/pem.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ func Decode(data []byte) (p *Block, rest []byte) {
9595
for {
9696
// If we've already tried parsing a block, skip past the END we already
9797
// saw.
98+
if endTrailerIndex < 0 || endTrailerIndex > len(rest) {
99+
return nil, data
100+
}
98101
rest = rest[endTrailerIndex:]
99102

100103
// Find the first END line, and then find the last BEGIN line before

0 commit comments

Comments
 (0)