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

"index out of range [3] with length 3" when app import "ethereum/go-ethereum/rpc" #524

Closed
SaigyoujiYuyuko233 opened this issue Apr 21, 2022 · 3 comments · Fixed by #526
Closed
Labels
bug Something isn't working
Milestone

Comments

@SaigyoujiYuyuko233
Copy link

What version of Garble and Go are you using?

$ garble version
v0.6.0
$ go version
go version go1.18.1 linux/amd64

What environment are you running Garble on?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/.local/share/gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/.local/share/gopath"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/opt/go-1.18.1/go1.18.1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go-1.18.1/go1.18.1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/root/eth-example/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build68359217=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. import pkg "https://github.com/ethereum/go-ethereum"
  2. call some function in the pkg
  3. run "garble build"

What did you expect to see?

Successfully build the application

What did you see instead?

GOOS=windows garble build -trimpath -ldflags "-s -w -extldflags '-static'" -gcflags=-trimpath=$GOPATH -asmflags=-trimpath=$GOPATH
# github.com/ethereum/go-ethereum/rpc
panic: runtime error: index out of range [3] with length 3

goroutine 1 [running]:
main.(*transformer).findReflectFunctions.func1.1({0x712d78?, 0xc000344800})
        /root/.local/share/gopath/pkg/mod/mvdan.cc/garble@v0.6.0/main.go:1116 +0x606
go/ast.inspector.Visit(0xc000900f30, {0x712d78?, 0xc000344800?})
        /opt/go-1.18.1/go1.18.1/src/go/ast/walk.go:387 +0x31
go/ast.Walk({0x712640?, 0xc000900f30?}, {0x712d78?, 0xc000344800?})
        /opt/go-1.18.1/go1.18.1/src/go/ast/walk.go:52 +0x62
go/ast.walkExprList({0x712640, 0xc000900f30}, {0xc00028b260?, 0x1, 0x4de971?})
        /opt/go-1.18.1/go1.18.1/src/go/ast/walk.go:26 +0x91
go/ast.Walk({0x712640?, 0xc000900f30?}, {0x712c38?, 0xc000344840?})
        /opt/go-1.18.1/go1.18.1/src/go/ast/walk.go:218 +0x1548
go/ast.walkStmtList({0x712640, 0xc000900f30}, {0xc000095800?, 0x5, 0xc00088f708?})
        /opt/go-1.18.1/go1.18.1/src/go/ast/walk.go:32 +0x91
go/ast.Walk({0x712640?, 0xc000900f30?}, {0x712d28?, 0xc000340720?})
        /opt/go-1.18.1/go1.18.1/src/go/ast/walk.go:235 +0x10e5
go/ast.Walk({0x712640?, 0xc000900f30?}, {0x712ff8?, 0xc000340750?})
        /opt/go-1.18.1/go1.18.1/src/go/ast/walk.go:358 +0x4b0
go/ast.Inspect(...)
        /opt/go-1.18.1/go1.18.1/src/go/ast/walk.go:399
main.(*transformer).findReflectFunctions.func1({0x712ff8?, 0xc000340750})
        /root/.local/share/gopath/pkg/mod/mvdan.cc/garble@v0.6.0/main.go:1099 +0x20e
main.(*transformer).findReflectFunctions(0xc000619380, {0xc00059b100?, 0x11, 0x20})
        /root/.local/share/gopath/pkg/mod/mvdan.cc/garble@v0.6.0/main.go:1150 +0x123
main.(*transformer).findReflectFunctions(0xc000619380, {0xc00059b100?, 0x11, 0x20})
        /root/.local/share/gopath/pkg/mod/mvdan.cc/garble@v0.6.0/main.go:1156 +0xda
main.(*transformer).findReflectFunctions(0xc000619380, {0xc00059b100?, 0x11, 0x20})
        /root/.local/share/gopath/pkg/mod/mvdan.cc/garble@v0.6.0/main.go:1156 +0xda
main.transformCompile({0xc000010260?, 0x22?, 0x22?})
        /root/.local/share/gopath/pkg/mod/mvdan.cc/garble@v0.6.0/main.go:717 +0x313
main.mainErr({0xc000010250, 0x23, 0x23})
        /root/.local/share/gopath/pkg/mod/mvdan.cc/garble@v0.6.0/main.go:386 +0x527
main.main1()
        /root/.local/share/gopath/pkg/mod/mvdan.cc/garble@v0.6.0/main.go:238 +0x16e
main.main()
        /root/.local/share/gopath/pkg/mod/mvdan.cc/garble@v0.6.0/main.go:136 +0x19
@SaigyoujiYuyuko233
Copy link
Author

SaigyoujiYuyuko233 commented Apr 21, 2022

I found out that this error start at go-ethereum v1.10.4.
go-ethereum v1.10.17 works with garble v0.3.0 and go v1.16.15.
But without garble, go-ethereum v1.10.17 works with go v1.18

@mvdan
Copy link
Member

mvdan commented Apr 22, 2022

Thanks for reporting! This is because of variadic functions, where the number of arguments may not match the number of parameters. I'm working on a fix.

@mvdan mvdan added the bug Something isn't working label Apr 22, 2022
mvdan added a commit to mvdan/garble-fork that referenced this issue Apr 22, 2022
When a function definition is variadic,
the number of parameters may not match the number of calling arguments.
Our existing code was a bit naive with this edge case,
leading to a panic when indexing call.Args.

Keep track of that information, and properly handle all variadic
arguments that may be used indirectly with reflection.

We add a test case that used to panic, where 0 arguments are used for a
variadic parameter, as well as a case where we need to disable
obfuscation for a Go type used as the second variadic argument rather
than the first.

Finally, the old code in findReflectFunctions looked at Go function
types from the point of view of go/ast.FuncType.
Use go/types.Signature instead, where we don't need to deal with the
grouping of variables in the original syntax, and which is more
consistent with the rest of the garble codebase.

Fixes burrowers#524.
@lu4p lu4p closed this as completed in #526 Apr 22, 2022
lu4p pushed a commit that referenced this issue Apr 22, 2022
When a function definition is variadic,
the number of parameters may not match the number of calling arguments.
Our existing code was a bit naive with this edge case,
leading to a panic when indexing call.Args.

Keep track of that information, and properly handle all variadic
arguments that may be used indirectly with reflection.

We add a test case that used to panic, where 0 arguments are used for a
variadic parameter, as well as a case where we need to disable
obfuscation for a Go type used as the second variadic argument rather
than the first.

Finally, the old code in findReflectFunctions looked at Go function
types from the point of view of go/ast.FuncType.
Use go/types.Signature instead, where we don't need to deal with the
grouping of variables in the original syntax, and which is more
consistent with the rest of the garble codebase.

Fixes #524.
@SaigyoujiYuyuko233
Copy link
Author

Wow! That is really fast! Thanks for your hard working!

@mvdan mvdan added this to the v0.6.0 milestone May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants