]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: don't panic if unsafe.Sizeof/Offsetof is used with oversize types
authorRobert Griesemer <gri@golang.org>
Thu, 23 Mar 2023 17:43:56 +0000 (10:43 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 27 Mar 2023 16:52:49 +0000 (16:52 +0000)
commit171850f16983a24bf2cf0340b0982838faa7f3c5
tree1666a15754d814f57e5646913fb2a6a2b054e652
parenta0c9d153e0c177677701b8a4e6e5eba5a6c44a4f
cmd/compile: don't panic if unsafe.Sizeof/Offsetof is used with oversize types

In the Sizes API, recognize an overflow (to a negative value) as a
consequence of an oversize value, and specify as such in the API.

Adjust the various size computations to take overflow into account.

Recognize a negative size or offset as an error and report it rather
than panicking.

Use the same protocol for results provided by the default (StdSizes)
and external Sizes implementations.

Add a new error code TypeTooLarge for the new errors.

Fixes #59190.
Fixes #59207.

Change-Id: I8c33a9e69932760275100112dde627289ac7695b
Reviewed-on: https://go-review.googlesource.com/c/go/+/478919
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
12 files changed:
src/cmd/compile/internal/noder/sizes.go
src/cmd/compile/internal/types2/builtins.go
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/sizes.go
src/go/types/builtins.go
src/go/types/expr.go
src/go/types/sizes.go
src/internal/types/errors/code_string.go
src/internal/types/errors/codes.go
src/internal/types/testdata/fixedbugs/issue59190.go [new file with mode: 0644]
src/internal/types/testdata/fixedbugs/issue59207.go [new file with mode: 0644]
test/fixedbugs/issue59190.go [new file with mode: 0644]