Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/gc: converting len(slice) value to non-fitting numeric types should result in overflow error #33643

Closed
nrvnrvn opened this issue Aug 14, 2019 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@nrvnrvn
Copy link
Contributor

nrvnrvn commented Aug 14, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.7

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
CC="clang"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_ENABLED="1"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
CXX="clang++"
GCCGO="gccgo"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lol/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/fq/v153jfj15jz73k94n8mzycl40000gn/T/go-build186400384=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOMOD="/mycoolproject/go.mod"
GOOS="darwin"
GOPATH="/Users/lol/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
PKG_CONFIG="pkg-config"

What did you do?

https://play.golang.org/p/4RP50Tv00i8

What did you expect to see?

https://play.golang.org/p/cvwZ7P8Fa_q

What did you see instead?

overflowing value is converted to 0

@zephyrtronium
Copy link
Contributor

This is closely related to #30613 and the various issues linked therefrom. That discussion might benefit from your use case for a checked uint8 type.

@andybons andybons changed the title converting len(slice) value to non-fitting numeric types should result in overflow error cmd/gc: converting len(slice) value to non-fitting numeric types should result in overflow error Aug 15, 2019
@andybons
Copy link
Member

@nrvnrvn are you expecting an error at compile time or runtime?

@andybons andybons added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Aug 15, 2019
@andybons andybons added this to the Unplanned milestone Aug 15, 2019
@nrvnrvn
Copy link
Contributor Author

nrvnrvn commented Aug 15, 2019

Good question. I would expect a runtime error.

@andybons
Copy link
Member

At first this seems like a dupe of #31500. Would you agree?

@mvdan
Copy link
Member

mvdan commented Jun 15, 2021

The latest iteration on guarding against overflows is #30209. I'd suggest to leave a comment there.

@mvdan mvdan closed this as completed Jun 15, 2021
@golang golang locked and limited conversation to collaborators Jun 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants