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/8g: Slice memory corruption when using uint64 indices #5820

Closed
karalabe opened this issue Jun 30, 2013 · 5 comments
Closed

cmd/8g: Slice memory corruption when using uint64 indices #5820

karalabe opened this issue Jun 30, 2013 · 5 comments

Comments

@karalabe
Copy link
Contributor

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.

If a slice element is set to nil using an uint64 index, the slice internals get
corrupted. Printing it for example will lead to a hard panic.
1. http://play.golang.org/p/y7UsO7uakx

What is the expected output?
[]

What do you see instead?
On x64 it works, on 386:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x1 pc=0x80681cd]

goroutine 1 [running]:
fmt.(*pp).fmtBytes(0x18221630, 0x1, 0x1, 0x1, 0x76, ...)
        /opt/google/go/src/pkg/fmt/print.go:561 +0x21d
fmt.(*pp).printField(0x18221630, 0x80b1ee0, 0x1822a020, 0x76, 0xf7270000, ...)
        /opt/google/go/src/pkg/fmt/print.go:802 +0x3d1
fmt.(*pp).doPrint(0x18221630, 0xf7278fb8, 0x1, 0x1, 0x8040101, ...)
        /opt/google/go/src/pkg/fmt/print.go:1143 +0x1a4
fmt.Fprintln(0x18263140, 0x18200098, 0xf7278fb8, 0x1, 0x1, ...)
        /opt/google/go/src/pkg/fmt/print.go:280 +0x63
fmt.Println(0xf7278fb8, 0x1, 0x1, 0x1, 0x0, ...)
        /opt/google/go/src/pkg/fmt/print.go:290 +0x63
main.main()
        /work/iris/src/github.com/karalabe/iris-test/main.go:11 +0x107

Which compiler are you using (5g, 6g, 8g, gccgo)?
barebone go run

Which operating system are you using?
openSuse 12.3, x64

Which version are you using?  (run 'go version')
go version go1.1.1 linux/amd64

Please provide any additional information below.
Interesting stuff:
Converting the int64 to int before setting the thing to nil works:
http://play.golang.org/p/5LugyIXvsH
Using int64 as the index and putting in anything else *but* nil works:
http://play.golang.org/p/QBbreOANRH

Go-nuts discussion on it: https://groups.google.com/forum/#!topic/golang-nuts/U1TctpfnEXM
@karalabe
Copy link
Contributor Author

Comment 1:

*Obviously using 386 as the architecture:
GOARCH=386 go run main.go

@DanielMorsing
Copy link
Contributor

Comment 2:

Labels changed: added priority-soon, go1.1.2, removed priority-triage.

Status changed to Accepted.

@DanielMorsing
Copy link
Contributor

Comment 3:

https://golang.org/cl/11383043/

Owner changed to @DanielMorsing.

Status changed to Started.

@DanielMorsing
Copy link
Contributor

Comment 4:

This issue was closed by revision 85a7c09.

Status changed to Fixed.

@adg
Copy link
Contributor

adg commented Jul 22, 2013

Comment 5:

This issue was closed by revision 384bc9cc2853.

@rsc rsc added this to the Go1.1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.1.2 label Apr 14, 2015
adg added a commit that referenced this issue May 11, 2015
…nter calculations.

««« CL 11383043 / dc24634de6c5
cmd/8g: Make clearfat non-interleaved with pointer calculations.

clearfat (used to zero initialize structures) will use AX for x86 block ops. If we write to AX while calculating the dest pointer, we will fill the structure with incorrect values.
Since 64-bit arithmetic uses AX to synthesize a 64-bit register, getting an adress by indexing with 64-bit ops can clobber the register.

Fixes #5820.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/11383043
»»»

Update #5928

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/11698043
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants