Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/fuzz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
fuzz:
if: ${{ github.repository == 'chainguard-dev/malcontent' && needs.discover.outputs.targets != '[]' }}
needs: discover
runs-on: ubuntu-latest-16-core
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
Expand All @@ -107,7 +107,7 @@ jobs:
--cap-add SETUID
--cap-drop ALL
--cgroupns private
--cpu-shares=16384
--cpu-shares=4096
--memory-swappiness=0
--security-opt no-new-privileges
--ulimit core=0
Expand All @@ -132,8 +132,9 @@ jobs:
run: |
make samples

# -parallel=1 is used for now due to this: https://github.com/golang/go/issues/56238
- name: Run fuzzer - ${{ matrix.target.test }}
env:
FUZZ_TIME: ${{ inputs.fuzz_time || '30s' }}
run: |
go test -timeout 0 -fuzz="${{ matrix.target.test }}" -fuzztime="${FUZZ_TIME}" "${{ matrix.target.package }}"
go test -parallel=1 -timeout 0 -fuzz="${{ matrix.target.test }}" -fuzztime="${FUZZ_TIME}" "${{ matrix.target.package }}"
20 changes: 10 additions & 10 deletions pkg/archive/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func FuzzExtractTar(f *testing.F) {
}
defer os.RemoveAll(tmpDir)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
_ = ExtractTar(ctx, tmpDir, tmpFile.Name())

Expand Down Expand Up @@ -134,7 +134,7 @@ func FuzzExtractZip(f *testing.F) {
}
defer os.RemoveAll(tmpDir)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
_ = ExtractZip(ctx, tmpDir, tmpFile.Name())

Expand Down Expand Up @@ -224,7 +224,7 @@ func FuzzExtractArchive(f *testing.F) {
}
tmpFile.Close()

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

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

_ = ExtractGzip(ctx, tmpDir, tmpFile.Name())
Expand Down Expand Up @@ -374,7 +374,7 @@ func FuzzExtractBz2(f *testing.F) {
}
defer os.RemoveAll(tmpDir)

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

_ = ExtractBz2(ctx, tmpDir, tmpFile.Name())
Expand Down Expand Up @@ -429,7 +429,7 @@ func FuzzExtractZstd(f *testing.F) {
}
defer os.RemoveAll(tmpDir)

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

_ = ExtractZstd(ctx, tmpDir, tmpFile.Name())
Expand Down Expand Up @@ -486,7 +486,7 @@ func FuzzExtractZlib(f *testing.F) {
}
defer os.RemoveAll(tmpDir)

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

_ = ExtractZlib(ctx, tmpDir, tmpFile.Name())
Expand Down Expand Up @@ -543,7 +543,7 @@ func FuzzExtractRPM(f *testing.F) {
}
defer os.RemoveAll(tmpDir)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

_ = ExtractRPM(ctx, tmpDir, tmpFile.Name())
Expand Down Expand Up @@ -597,7 +597,7 @@ func FuzzExtractDeb(f *testing.F) {
}
defer os.RemoveAll(tmpDir)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

_ = ExtractDeb(ctx, tmpDir, tmpFile.Name())
Expand Down Expand Up @@ -641,7 +641,7 @@ func FuzzExtractUPX(f *testing.F) {
}
defer os.RemoveAll(tmpDir)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

_ = ExtractUPX(ctx, tmpDir, tmpFile.Name())
Expand Down
12 changes: 9 additions & 3 deletions pkg/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,24 @@ func loadCachedRules(cacheFile string) (*yarax.Rules, error) {

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

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

if err := f.Close(); err != nil {
os.Remove(tmpFile)
return fmt.Errorf("close cache file: %w", err)
}

if err := os.Rename(tmpFile, cacheFile); err != nil {
os.Remove(tmpFile)
return fmt.Errorf("rename cache file: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/programkind/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func FuzzFile(f *testing.F) {
}
tmpFile.Close()

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

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