go-fuzz: go-fuzz-build fails with Go 1.15 due to uncertain position of comments
failed case 1:
# yyc @ Yichens-MacBook-Pro in ~/GolandProjects/fuzz-test/fuzz on git:go-ast-bug-demo x [9:58:01] C:1
$ go-fuzz-build
failed to execute go build: exit status 2
# fuzz-test/fuzz
/Users/yyc/GolandProjects/fuzz-test/fuzz/fuzzer.go:3: misplaced compiler directive
# yyc @ Yichens-MacBook-Pro in ~/GolandProjects/fuzz-test/fuzz on git:go-ast-bug-demo x [10:07:06] C:1
$ cat fuzzer.go
package fuzz
//go:noescape
func foo() {}
func Fuzz(input []byte) int {
foo()
return 0
}
go-fuzz-build will transform the input file to the following, which is obviously incorrect:
//line /Users/yyc/GolandProjects/fuzz-test/fuzz/fuzzer.go:1
package fuzz
//line /Users/yyc/GolandProjects/fuzz-test/fuzz/fuzzer.go:1
import
//go:noescape
//line /Users/yyc/GolandProjects/fuzz-test/fuzz/fuzzer.go:1
_go_fuzz_dep_ "go-fuzz-dep"
//line /Users/yyc/GolandProjects/fuzz-test/fuzz/fuzzer.go:4
func foo() { _go_fuzz_dep_.CoverTab[22588]++ }
func Fuzz(input []byte) int {
//line /Users/yyc/GolandProjects/fuzz-test/fuzz/fuzzer.go:6
_go_fuzz_dep_.CoverTab[44810]++
foo()
return 0
}
//line /Users/yyc/GolandProjects/fuzz-test/fuzz/fuzzer.go:9
var _ = _go_fuzz_dep_.CoverTab
I found this probably a go bug and submitted an issue: https://github.com/golang/go/issues/40546 I’ve also fixed this import issue with an ugly patch: https://github.com/oraluben/go-fuzz/tree/fix-import, but that does not overcome this issue, see case 2:
failed case 2
# yyc @ Yichens-MacBook-Pro in ~/GolandProjects/fuzz-test/fuzz on git:go-ast-bug-demo x [10:17:46] C:130
$ go-fuzz-build
failed to execute go build: exit status 2
# reflect
/Users/yyc/go/go1.15beta1/src/reflect/value.go:1425: misplaced compiler directive
# yyc @ Yichens-MacBook-Pro in ~/GolandProjects/fuzz-test/fuzz on git:go-ast-bug-demo x [10:17:57] C:1
$ cat fuzzer.go
package fuzz
import "reflect"
func Fuzz(input []byte) int {
reflect.DeepEqual(1, 1)
return 0
}
the source: https://github.com/golang/go/blob/master/src/reflect/value.go#L1421-L1451 the transformed code:
//line /Users/yyc/go/go1.15beta1/src/reflect/value.go:1420
return __gofuzz_v1 !=
//line /Users/yyc/go/go1.15beta1/src/reflect/value.go:1425
//go:nocheckptr
//line /Users/yyc/go/go1.15beta1/src/reflect/value.go:1420
__gofuzz_v2
//line /Users/yyc/go/go1.15beta1/src/reflect/value.go:1420
}() == true
//line /Users/yyc/go/go1.15beta1/src/reflect/value.go:1420
default:
//line /Users/yyc/go/go1.15beta1/src/reflect/value.go:1420
_go_fuzz_dep_.CoverTab[7638]++
}
//line /Users/yyc/go/go1.15beta1/src/reflect/value.go:1421
}
//line /Users/yyc/go/go1.15beta1/src/reflect/value.go:1421
_go_fuzz_dep_.CoverTab[54290]++
panic(&ValueError{"reflect.Value.OverflowUint", v.kind()})
}
you can find //go:nocheckptr was inserted in the middle.
I found it not easy to fix this without fixing the printer’s logic, maybe you would have more idea about how to workaround this in go-fuzz-build?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 38 (8 by maintainers)
Commits related to this issue
- Fix #294 for reflect/value.go — committed to oraluben/go-fuzz by oraluben 4 years ago
- Fix #294 for reflect/value.go — committed to oraluben/go-fuzz by oraluben 4 years ago
- .github/workflows: switch fuzzit to syz-old-env Use syz-old-env because it contains Go 1.14. syz-env contains Go 1.15 and go-fuzz is broken with Go 1.15: https://github.com/dvyukov/go-fuzz/issues/294 — committed to dvyukov/syzkaller by dvyukov 4 years ago
- .github/workflows: switch fuzzit to syz-old-env Use syz-old-env because it contains Go 1.14. syz-env contains Go 1.15 and go-fuzz is broken with Go 1.15: https://github.com/dvyukov/go-fuzz/issues/294 — committed to dvyukov/syzkaller by dvyukov 4 years ago
- .github/workflows: switch fuzzit to syz-old-env Use syz-old-env because it contains Go 1.14. syz-env contains Go 1.15 and go-fuzz is broken with Go 1.15: https://github.com/dvyukov/go-fuzz/issues/294 — committed to google/syzkaller by dvyukov 4 years ago
- go-fuzz-build: set position of BinaryExpr in sonar Fixes #294 — committed to josharian/go-fuzz by josharian 4 years ago
- go-fuzz-build: set position of BinaryExpr in sonar Fixes #294 — committed to dvyukov/go-fuzz by josharian 4 years ago
- go-fuzz-build: parenthesize imports And give them a plausible position. Fixes #294 again, hopefully for the last time — committed to josharian/go-fuzz by josharian 4 years ago
- Updated to latest golang https://github.com/dvyukov/go-fuzz/issues/294 has been fixed hence we can update to 1.15.5 — committed to degeri/dcrd-continuous-fuzz by degeri 4 years ago
works now 🎉 Double checked on a fresh docker
I’m also running into this
Same issue, this happens with Go 1.15 and throws a warning for the following files:
Thank you @dvyukov for this project, and thank you everyone involved in this fix!
Thanks, @danp. Based on that, I’ve merged the PR. Hopefully it’ll be easier to test now.