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

Most upvoted comments

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:

/usr/lib/go/src/vendor/golang.org/x/crypto/poly1305/sum_amd64.go:9: misplaced compiler directive
/usr/lib/go/src/crypto/sha256/sha256block_decl.go:9: misplaced compiler directive
/usr/lib/go/src/reflect/value.go:1432: misplaced compiler directive

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.