google / google/oss-fuzz

Go Native: Support for embed files

Open
#9,267 2 comments 2 reactions 1 assignee Claimed by @AdamKorcz View on GitHub
Dominant language
Shell
Stars
12.6k
Forks
2.9k
Avg merge
2d 2h
Merged PRs (30d)
62

Description

The project `fluxcd` has two tests that relies on files [being embedded](https://pkg.go.dev/embed) during the building process in order to execute properly during fuzzing.

After debugging the two issues below I noticed that the current `compile_native_go_fuzzer`/`go-118-fuzz-build` does not seem to support it.

`FuzzRandomGitFiles` ([Issue 53833](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=53833))
- Files are being copied to the right location during [pre-build](https://github.com/fluxcd/source-controller/blob/c74180503c5037feaf5d7ec69b858b149a868213/tests/fuzz/oss_fuzz_prebuild.sh#L24-L25).
- File locations are correctly set on the [test file](https://github.com/fluxcd/source-controller/blob/c74180503c5037feaf5d7ec69b858b149a868213/controllers/gitrepository_controller_fuzz_test.go#L84-L86).

`Fuzz_Controllers` ([Issue 54247](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54247))
- Files are being copied to the right location during [pre-build](https://github.com/fluxcd/kustomize-controller/blob/803349d1c25b2d3aa8b5aac36054d7357dccd529/tests/fuzz/oss_fuzz_prebuild.sh#L24-L25).
- File locations are correctly set on the [test file](https://github.com/fluxcd/kustomize-controller/blob/803349d1c25b2d3aa8b5aac36054d7357dccd529/controllers/kustomization_fuzzer_test.go#L81-L84).

However, at execution time the files are not available:
```
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 2857393218
INFO: Loaded 1 modules (433268 inline 8-bit counters): 433268 [0x6bacb90, 0x6c16804),
INFO: Loaded 1 PC tables (433268 PCs): 433268 [0x10c000100000,0x10c00079c740),
/home/levi/go/src/github.com/fluxcd/kustomize-controller/build/fuzz/out/Fuzz_Controllers: Running 1 inputs 1 time(s) each.
Running: /home/levi/Downloads/clusterfuzz-testcase-Fuzz_Controllers-4728810836983808
Data input length: 1024
panic: unable to install CRDs onto control plane: unable to read CRD files: stat testdata/crd: no such file or directory [recovered]
panic: unable to install CRDs onto control plane: unable to read CRD files: stat testdata/crd: no such file or directory

goroutine 17 [running, locked to thread]:
main.catchPanics()
github.com/fluxcd/kustomize-controller/main.1293939325.go:49 +0x35c
panic({0x4a48e80, 0x10c000fa99c8})
runtime/panic.go:884 +0x212
github.com/fluxcd/pkg/runtime/testenv.New({0x10c0000eca70, 0x1, 0x6b9e120?})
github.com/fluxcd/pkg/runtime@v0.24.0/testenv/testenv.go:152 +0x929
github.com/fluxcd/kustomize-controller/controllers.runInContext(0x4cd6990, 0x10c000c54e80, {0x4090905, 0xc})
github.com/fluxcd/kustomize-controller/controllers/kustomization_fuzzer_test.go_fuzz.go:408 +0x305
github.com/fluxcd/kustomize-controller/controllers.Fuzz_Controllers.func1(0x579c2c?, {0x61a000000684, 0xfb, 0x539}, {0x61a000000783, 0x400, 0x43a})
github.com/fluxcd/kustomize-controller/controllers/kustomization_fuzzer_test.go_fuzz.go:81 +0x41a
reflect.Value.call({0x48f04c0?, 0x4cd6998?, 0x13?}, {0x407f930, 0x4}, {0x10c000c86240, 0x3, 0x4?})
reflect/value.go:584 +0x1bce
reflect.Value.Call({0x48f04c0?, 0x4cd6998?, 0x4084e3e?}, {0x10c000c86240, 0x3, 0x4})
reflect/value.go:368 +0x1fa
github.com/AdamKorcz/go-118-fuzz-build/testing.(*F).Fuzz(0x10c0000aad98, {0x48f04c0?, 0x4cd6998})
github.com/AdamKorcz/go-118-fuzz-build@v0.0.0-20221219200756-befc80a21334/testing/f.go:177 +0x9ab
github.com/fluxcd/kustomize-controller/controllers.Fuzz_Controllers(0x0?)
github.com/fluxcd/kustomize-controller/controllers/kustomization_fuzzer_test.go_fuzz.go:65 +0x65
main.LibFuzzerFuzz_Controllers({0x61a000000680, 0x53d, 0x53d})
github.com/fluxcd/kustomize-controller/main.1293939325.go:31 +0x133
main.LLVMFuzzerTestOneInput(0x61a000000680, 0x53d)
github.com/fluxcd/kustomize-controller/main.1293939325.go:24 +0xa5
```

(cc @hiddeco @stefanprodan)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.