From: Jorropo Date: Fri, 15 Apr 2022 22:02:21 +0000 (+0000) Subject: go/doc: fix incorrect identifier parsing in comments X-Git-Tag: go1.19beta1~650 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e704ef2b8529119a11694b4cb15215d3dd6b0a9f;p=gostls13.git go/doc: fix incorrect identifier parsing in comments This code was trying to iterate codepoints, but didn't reslice the string, so it was reading the first codepoint over and over, if the string length was not a multiple of the first codepoint length, this would cause to overshoot past the end of the string. This was a latent bug introduced in CL 384265 but was revealed to Ngolo-fuzzing in OSS-Fuzz in CL 397277. Fixes #52353 Change-Id: I13f0352e6ad13a42878927f3b1c18c58360dd40c GitHub-Last-Rev: 424f6cfad1bc7d66314911e6b4b4ce6751330435 GitHub-Pull-Request: golang/go#52356 Reviewed-on: https://go-review.googlesource.com/c/go/+/400240 Reviewed-by: Dmitri Shuralyov Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- diff --git a/src/go/doc/comment/parse.go b/src/go/doc/comment/parse.go index a8cba90ec0..83b37c32c5 100644 --- a/src/go/doc/comment/parse.go +++ b/src/go/doc/comment/parse.go @@ -1063,7 +1063,7 @@ func ident(s string) (id string, ok bool) { } break } - r, nr := utf8.DecodeRuneInString(s) + r, nr := utf8.DecodeRuneInString(s[n:]) if unicode.IsLetter(r) { n += nr continue diff --git a/src/go/doc/comment/parse_test.go b/src/go/doc/comment/parse_test.go new file mode 100644 index 0000000000..bce733eaae --- /dev/null +++ b/src/go/doc/comment/parse_test.go @@ -0,0 +1,12 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package comment + +import "testing" + +// See https://golang.org/issue/52353 +func Test52353(t *testing.T) { + ident("𫕐ﯯ") +}