Skip to content

Commit dd6d780

Browse files
authored
chore: run fuzzers with -parallel=1 (#1367)
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
1 parent 02f42d4 commit dd6d780

4 files changed

Lines changed: 24 additions & 17 deletions

File tree

.github/workflows/fuzz.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
fuzz:
9393
if: ${{ github.repository == 'chainguard-dev/malcontent' && needs.discover.outputs.targets != '[]' }}
9494
needs: discover
95-
runs-on: ubuntu-latest-16-core
95+
runs-on: ubuntu-latest
9696
permissions:
9797
contents: read
9898
strategy:
@@ -107,7 +107,7 @@ jobs:
107107
--cap-add SETUID
108108
--cap-drop ALL
109109
--cgroupns private
110-
--cpu-shares=16384
110+
--cpu-shares=4096
111111
--memory-swappiness=0
112112
--security-opt no-new-privileges
113113
--ulimit core=0
@@ -132,8 +132,9 @@ jobs:
132132
run: |
133133
make samples
134134
135+
# -parallel=1 is used for now due to this: https://github.com/golang/go/issues/56238
135136
- name: Run fuzzer - ${{ matrix.target.test }}
136137
env:
137138
FUZZ_TIME: ${{ inputs.fuzz_time || '30s' }}
138139
run: |
139-
go test -timeout 0 -fuzz="${{ matrix.target.test }}" -fuzztime="${FUZZ_TIME}" "${{ matrix.target.package }}"
140+
go test -parallel=1 -timeout 0 -fuzz="${{ matrix.target.test }}" -fuzztime="${FUZZ_TIME}" "${{ matrix.target.package }}"

pkg/archive/fuzz_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func FuzzExtractTar(f *testing.F) {
7676
}
7777
defer os.RemoveAll(tmpDir)
7878

79-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
79+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
8080
defer cancel()
8181
_ = ExtractTar(ctx, tmpDir, tmpFile.Name())
8282

@@ -134,7 +134,7 @@ func FuzzExtractZip(f *testing.F) {
134134
}
135135
defer os.RemoveAll(tmpDir)
136136

137-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
137+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
138138
defer cancel()
139139
_ = ExtractZip(ctx, tmpDir, tmpFile.Name())
140140

@@ -224,7 +224,7 @@ func FuzzExtractArchive(f *testing.F) {
224224
}
225225
tmpFile.Close()
226226

227-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
227+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
228228
defer cancel()
229229
cfg := malcontent.Config{}
230230
extractedDir, err := ExtractArchiveToTempDir(ctx, cfg, tmpFile.Name())
@@ -327,7 +327,7 @@ func FuzzExtractGzip(f *testing.F) {
327327
}
328328
defer os.RemoveAll(tmpDir)
329329

330-
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
330+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
331331
defer cancel()
332332

333333
_ = ExtractGzip(ctx, tmpDir, tmpFile.Name())
@@ -374,7 +374,7 @@ func FuzzExtractBz2(f *testing.F) {
374374
}
375375
defer os.RemoveAll(tmpDir)
376376

377-
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
377+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
378378
defer cancel()
379379

380380
_ = ExtractBz2(ctx, tmpDir, tmpFile.Name())
@@ -429,7 +429,7 @@ func FuzzExtractZstd(f *testing.F) {
429429
}
430430
defer os.RemoveAll(tmpDir)
431431

432-
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
432+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
433433
defer cancel()
434434

435435
_ = ExtractZstd(ctx, tmpDir, tmpFile.Name())
@@ -486,7 +486,7 @@ func FuzzExtractZlib(f *testing.F) {
486486
}
487487
defer os.RemoveAll(tmpDir)
488488

489-
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
489+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
490490
defer cancel()
491491

492492
_ = ExtractZlib(ctx, tmpDir, tmpFile.Name())
@@ -543,7 +543,7 @@ func FuzzExtractRPM(f *testing.F) {
543543
}
544544
defer os.RemoveAll(tmpDir)
545545

546-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
546+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
547547
defer cancel()
548548

549549
_ = ExtractRPM(ctx, tmpDir, tmpFile.Name())
@@ -597,7 +597,7 @@ func FuzzExtractDeb(f *testing.F) {
597597
}
598598
defer os.RemoveAll(tmpDir)
599599

600-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
600+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
601601
defer cancel()
602602

603603
_ = ExtractDeb(ctx, tmpDir, tmpFile.Name())
@@ -641,7 +641,7 @@ func FuzzExtractUPX(f *testing.F) {
641641
}
642642
defer os.RemoveAll(tmpDir)
643643

644-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
644+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
645645
defer cancel()
646646

647647
_ = ExtractUPX(ctx, tmpDir, tmpFile.Name())

pkg/compile/compile.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,24 @@ func loadCachedRules(cacheFile string) (*yarax.Rules, error) {
287287

288288
// saveCachedRules saves rules to a local file.
289289
func saveCachedRules(compiledRules *yarax.Rules, cacheFile string) error {
290-
tmpFile := cacheFile + ".tmp"
291-
f, err := os.OpenFile(tmpFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o600)
290+
cacheDir := filepath.Dir(cacheFile)
291+
f, err := os.CreateTemp(cacheDir, ".rules-*.cache.tmp")
292292
if err != nil {
293293
return fmt.Errorf("create cache file: %w", err)
294294
}
295-
defer f.Close()
295+
tmpFile := f.Name()
296296

297297
if _, err := compiledRules.WriteTo(f); err != nil {
298+
f.Close()
298299
os.Remove(tmpFile)
299300
return fmt.Errorf("write rules to cache: %w", err)
300301
}
301302

303+
if err := f.Close(); err != nil {
304+
os.Remove(tmpFile)
305+
return fmt.Errorf("close cache file: %w", err)
306+
}
307+
302308
if err := os.Rename(tmpFile, cacheFile); err != nil {
303309
os.Remove(tmpFile)
304310
return fmt.Errorf("rename cache file: %w", err)

pkg/programkind/fuzz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func FuzzFile(f *testing.F) {
8585
}
8686
tmpFile.Close()
8787

88-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
88+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
8989
defer cancel()
9090

9191
ft, err := File(ctx, tmpFile.Name())

0 commit comments

Comments
 (0)