segmentio/asm

"checkptr: pointer arithmetic result points to invalid allocation" on ARM

aaron42net opened this issue · 2 comments

While running a test suite on Go 1.17.3 on an M1 Mac with github.com/segmentio/encoding v0.3.2 and github.com/segmentio/asm v1.1.0, I ran into segmentio/encoding#84 again. I believe the fix in segmentio/encoding#85 was incomplete and may not apply to non-Intel CPUs, or maybe the rules are slightly different in newer Go and/or on ARM.

The same test code triggers it:

package main

import (
	"testing"

	"github.com/segmentio/encoding/json"
)

type Foo struct {
	Source struct {
		Table string
	}
}

func TestUnmarshal(t *testing.T) {
	input := []byte(`{"source": {"table": "1234567"}}`)
	r := &Foo{}
	json.Unmarshal(input, r)
}

Run the same way:

go mod init segtest
go mod tidy
go test -v -race -trimpath ./...

And the results are:

=== RUN   TestUnmarshal
fatal error: checkptr: pointer arithmetic result points to invalid allocation

goroutine 35 [running]:
runtime.throw({0x1010ceb85, 0x40})
	runtime/panic.go:1198 +0x54 fp=0xc00004cb00 sp=0xc00004cad0 pc=0x100f81794
runtime.checkptrArithmetic(0xc00016a040, {0xc00004cb90, 0x1, 0x1})
	runtime/checkptr.go:69 +0xbc fp=0xc00004cb30 sp=0xc00004cb00 pc=0x100f5106c
github.com/segmentio/asm/ascii.ValidPrintString({0xc00016a020, 0x20})
	github.com/segmentio/asm@v1.1.0/ascii/valid_print_default.go:16 +0x80 fp=0xc00004cba0 sp=0xc00004cb30 pc=0x101092be0
github.com/segmentio/asm/ascii.ValidPrint(...)
	github.com/segmentio/asm@v1.1.0/ascii/valid_print.go:7
github.com/segmentio/encoding/ascii.ValidPrint(...)
	github.com/segmentio/encoding@v0.3.2/ascii/valid_print.go:10
github.com/segmentio/encoding/json.internalParseFlags({0xc00016a020, 0x20, 0x20})
	github.com/segmentio/encoding@v0.3.2/json/parse.go:33 +0x148 fp=0xc00004cc50 sp=0xc00004cba0 pc=0x1010b9788
github.com/segmentio/encoding/json.Parse({0xc00016a020, 0x20, 0x20}, {0x101113200, 0xc000112530}, 0x0)
	github.com/segmentio/encoding@v0.3.2/json/json.go:303 +0xc8 fp=0xc00004cdb0 sp=0xc00004cc50 pc=0x1010b91c8
github.com/segmentio/encoding/json.Unmarshal({0xc00016a020, 0x20, 0x20}, {0x101113200, 0xc000112530})
	github.com/segmentio/encoding@v0.3.2/json/json.go:285 +0x58 fp=0xc00004ce60 sp=0xc00004cdb0 pc=0x1010b8ff8
segtest.TestUnmarshal(0xc000107520)
	segtest/seg_test.go:18 +0xe4 fp=0xc00004cec0 sp=0xc00004ce60 pc=0x1010c3584
testing.tRunner(0xc000107520, 0x1011405f0)
	testing/testing.go:1259 +0x19c fp=0xc00004cfc0 sp=0xc00004cec0 pc=0x101035e1c
runtime.goexit()
	runtime/asm_arm64.s:1133 +0x4 fp=0xc00004cfc0 sp=0xc00004cfc0 pc=0x100fb59f4
created by testing.(*T).Run
	testing/testing.go:1306 +0x5bc

I've tried to run on an Intel CPU with -tags purego, but it won't compile due to duplicated function definitions. Perhaps add a build !purego to the generated _amd64.go files to get this to work and add go test -race -tags purego to your test suite?

Thanks!
-- Aaron

Thanks for the report @aaron42net

It seems we could improve our automated tests to detect issues when compiling with purego or testing with -race on different architectures 👍

If you are able to help, we would always welcome contributions!

@aaron42net thanks for the report! this is fixed by #64 and segmentio/encoding#111