]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.15] bytes, internal/bytealg: fix incorrect IndexString usage
authorMichael Munday <mike.munday@ibm.com>
Wed, 23 Sep 2020 10:58:52 +0000 (03:58 -0700)
committerDmitri Shuralyov <dmitshur@golang.org>
Wed, 7 Oct 2020 21:02:58 +0000 (21:02 +0000)
commitaf06e65910fc976c63a65decd2881ba34114428f
tree0057f46f7a1920d142e4e83dde47847a961e666d
parent884179022e0f57d6cf26a5fb12695a33dc1780fc
[release-branch.go1.15] bytes, internal/bytealg: fix incorrect IndexString usage

The IndexString implementation in the bytealg package requires that
the string passed into it be in the range '2 <= len(s) <= MaxLen'
where MaxLen may be any value (including 0).

CL 156998 added calls to bytealg.IndexString where MaxLen was not
first checked. This led to an illegal instruction on s390x with
the vector facility disabled.

This CL guards the calls to bytealg.IndexString with a MaxLen check.
If the check fails then the code now falls back to the pre CL 156998
implementation (a loop over the runes in the string).

Since the MaxLen check is now in place the generic implementation is
no longer called so I have returned it to its original unimplemented
state.

In future we may want to drop MaxLen to prevent this kind of
confusion.

Fixes #41595.

Change-Id: I81d88cf8c5ae143a8f5f460d18f8269cb6c0f28c
Reviewed-on: https://go-review.googlesource.com/c/go/+/256921
Trust: Michael Munday <mike.munday@ibm.com>
Run-TryBot: Michael Munday <mike.munday@ibm.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
src/bytes/bytes.go
src/internal/bytealg/index_generic.go