x86/x86asm: fix panic on truncated VEX/EVEX prefix

decodeAVX guards every read from src except the opcode byte itself, so a
stream ending exactly at the end of a VEX or EVEX prefix indexes out of
range instead of reporting a truncated instruction:

	c5 fc         panic: index out of range [2] with length 2
	c4 e2 7d      panic: index out of range [3] with length 3
	62 f1 7c 48   panic: index out of range [4] with length 4

Add the missing bounds check and extend TestDecodeDoesNotCrash with the
three prefix forms.

Fixes golang/go#81447.

Change-Id: Id68526e432646ea95d2c1b84d715444ad2d4fb9a
GitHub-Last-Rev: 2a9c2bcbcd58bf223e12b76e9821baf50829dff8
GitHub-Pull-Request: golang/arch#25
Reviewed-on: https://go-review.googlesource.com/c/arch/+/830644
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2 files changed
tree: 7bc2784c8bd25937adb566e4b33877b4cd22b8e3
  1. arm/
  2. arm64/
  3. loong64/
  4. ppc64/
  5. riscv64/
  6. s390x/
  7. x86/
  8. .gitattributes
  9. codereview.cfg
  10. CONTRIBUTING.md
  11. go.mod
  12. go.sum
  13. LICENSE
  14. PATENTS
  15. README.md
README.md

arch

Go Reference

This repository holds machine architecture information used by the Go toolchain. The parts needed in the main Go repository are copied in.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/arch.

The main issue tracker for the arch repository is located at https://go.dev/issues. Prefix your issue with “x/arch:” in the subject line, so it is easy to find.