X Tutup
Skip to content

Commit a963242

Browse files
authored
Merge pull request containerd#5779 from AdamKorcz/fuzz4
2 parents a137b64 + 2556aac commit a963242

File tree

9 files changed

+655
-4
lines changed

9 files changed

+655
-4
lines changed

contrib/fuzz/archive_fuzzer.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// +build gofuzz
2+
3+
/*
4+
Copyright The containerd Authors.
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package fuzz
17+
18+
import (
19+
"bytes"
20+
"context"
21+
"io/ioutil"
22+
"os"
23+
24+
fuzz "github.com/AdaLogics/go-fuzz-headers"
25+
26+
"github.com/containerd/containerd/archive"
27+
)
28+
29+
// FuzzApply implements a fuzzer that applies
30+
// a fuzzed tar archive on a directory
31+
func FuzzApply(data []byte) int {
32+
f := fuzz.NewConsumer(data)
33+
iters, err := f.GetInt()
34+
if err != nil {
35+
return 0
36+
}
37+
maxIters := 20
38+
tmpDir, err := ioutil.TempDir("", "prefix-test")
39+
if err != nil {
40+
return 0
41+
}
42+
defer os.RemoveAll(tmpDir)
43+
for i := 0; i < iters%maxIters; i++ {
44+
rBytes, err := f.TarBytes()
45+
if err != nil {
46+
return 0
47+
}
48+
r := bytes.NewReader(rBytes)
49+
_, _ = archive.Apply(context.Background(), tmpDir, r)
50+
}
51+
return 1
52+
}

contrib/fuzz/oss_fuzz_build.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
cd "$(dirname "${BASH_SOURCE[0]}")"
1818
cd ../../
1919

20-
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzFiltersParse fuzz_filters_parse
21-
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzPlatformsParse fuzz_platforms_parse
22-
20+
# Don't move docker_fuzzer.go back into contrib/fuzz
2321
mv contrib/fuzz/docker_fuzzer.go remotes/docker/
2422
compile_go_fuzzer github.com/containerd/containerd/remotes/docker FuzzFetcher fuzz_fetcher
25-
mv remotes/docker/docker_fuzzer.go contrib/fuzz/
23+
24+
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzFiltersParse fuzz_filters_parse
25+
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzPlatformsParse fuzz_platforms_parse
26+
compile_go_fuzzer github.com/containerd/containerd/contrib/fuzz FuzzApply fuzz_apply

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/containerd/containerd
33
go 1.16
44

55
require (
6+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20210715213245-6c3934b029d8
67
github.com/Microsoft/go-winio v0.5.0
78
github.com/Microsoft/hcsshim v0.8.18
89
github.com/containerd/aufs v1.0.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiy
2222
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
2323
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
2424
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
25+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20210715213245-6c3934b029d8 h1:V8krnnfGj4pV65YLUm3C0/8bl7V5Nry2Pwvy3ru/wLc=
26+
github.com/AdaLogics/go-fuzz-headers v0.0.0-20210715213245-6c3934b029d8/go.mod h1:CzsSbkDixRphAF5hS6wbMKq0eI6ccJRb7/A0M6JBnwg=
2527
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
2628
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
2729
github.com/Azure/go-autorest/autorest v0.11.1/go.mod h1:JFgpikqFJ/MleTTxwepExTKnFUKKszPS8UavbQYUMuw=

vendor/github.com/AdaLogics/go-fuzz-headers/LICENSE

Lines changed: 201 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/AdaLogics/go-fuzz-headers/README.md

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
X Tutup