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

runtime: nacl/amd64p32's IndexByte overflow on extremely large lengths #24187

Closed
josharian opened this issue Mar 1, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@josharian
Copy link
Contributor

commented Mar 1, 2018

package main

import (
	"bytes"
	"fmt"
	"unsafe"
)

func main() {
	b := make([]byte, 128)
	for i := range b {
		b[i] = 1
	}
	if bytes.IndexByte(b, 0) != -1 {
		panic("found 0")
	}
	for i := range b {
		b[i] = 0
		c := b
		*(*int)(unsafe.Pointer(uintptr(unsafe.Pointer(&c)) + unsafe.Sizeof(uintptr(0)))) = 1<<31 - 1
		if bytes.IndexByte(c, 0) != i {
			fmt.Printf("missing 0 at %d\n", i)
		}
		b[i] = 1
	}
}

This succeeds with GOOS=darwin GOARCH=amd64 and GOOS=darwin GOARCH=386 but fails with GOOS=nacl GOARCH=amd64p32 for all i >= 15.

The problem is overflow in runtime·indexbytebody.

This is what was causing the trybot failures in CL 97523.

@josharian josharian added the NeedsFix label Mar 1, 2018

@josharian josharian added this to the Go1.11 milestone Mar 1, 2018

@josharian josharian self-assigned this Mar 1, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Mar 1, 2018

Change https://golang.org/cl/97802 mentions this issue: runtime: fix amd64p32 indexbytes in presence of overflow

@gopherbot gopherbot closed this in aa9c1a8 Mar 1, 2018

@golang golang locked and limited conversation to collaborators Mar 1, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.