-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: append does not fail when length overflows #29190
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
Comments
With Go 1.6 and gccgo I get the following crash. With Go 1.7 and later the program succeeds incorrectly. I'm going to mark this a release blocker for 1.13, but of course if we have a fix for 1.12 that would be nice.
|
From a quick look and test I think we can fix the issue by changing the comparison from INT to UINT here (and assuming no one will ever write code appending more than MaxInt arguments in a single append call - which likely would result in the parser running out of memory first): go/src/cmd/compile/internal/gc/ssa.go Line 2457 in d70b0ec
With that change I get:
The go/src/cmd/compile/internal/gc/walk.go Line 2649 in d70b0ec
Will send a CL for go1.12 after some more testing and writing a test case within the next day. |
Does that include |
Sorry I meant MaxInt before (updated the comment). |
Change https://golang.org/cl/154037 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Run the following app:
A slightly modified version is available and reproduces the error on the Go Playground: https://play.golang.org/p/AUKUBmQld_e
On the Playground
math.MaxInt32
is used instead ofmath.MaxInt64
.What did you expect to see?
A panic saying:
What did you see instead?
The app did not fail. Capacity stops growing when it reaches
MaxInt64
on 64-bit architecture, andMaxInt32
on 32-bit architectures, but length overflows and becomes negative.This is in clear violation of the Spec: Length and capacity:
as length becomes negative (and thus less than 0).
This report originates from this Stackoverflow question: https://stackoverflow.com/questions/53743099/behavior-of-append-when-appending-item-to-a-max-size-slice
The text was updated successfully, but these errors were encountered: