aboutsummaryrefslogtreecommitdiffstats
path: root/prog/mutation.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-12-17 11:59:24 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-12-22 10:11:08 +0100
commit8482d3c1035095c89d112c75bfcc2e4095b486bf (patch)
treef2cc2b32e55fd61cbcd03d1b27693fe7c972f07b /prog/mutation.go
parent412eecf40d514f89060844dc8631f60b80d7bfd2 (diff)
pkg/image: factor out from prog
Move image compression-related function to a separate package. In preperation for subsequent changes that make decompression more complex. Prog package is already large and complex. Also makes running compression tests/benchmarks much faster.
Diffstat (limited to 'prog/mutation.go')
-rw-r--r--prog/mutation.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/prog/mutation.go b/prog/mutation.go
index 96e11516c..100c47a91 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -10,6 +10,8 @@ import (
"math/rand"
"sort"
"sync"
+
+ "github.com/google/syzkaller/pkg/image"
)
// Maximum length of generated binary blobs inserted into the program.
@@ -385,21 +387,21 @@ func (t *BufferType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []
var imageMu sync.Mutex
-func (r *randGen) mutateImage(image []byte) (data []byte, retry bool) {
- if len(image) == 0 {
- return image, true
+func (r *randGen) mutateImage(compressed []byte) (data []byte, retry bool) {
+ if len(compressed) == 0 {
+ return compressed, true
}
// Don't decompress more than one image at a time
// since it can consume lots of memory.
// Reconsider when/if we move mutation to the host process.
imageMu.Lock()
defer imageMu.Unlock()
- data, err := Decompress(image)
+ data, err := image.Decompress(compressed)
if err != nil {
panic(fmt.Sprintf("could not decompress data: %v", err))
}
if len(data) == 0 {
- return image, true // Do not mutate empty data.
+ return compressed, true // Do not mutate empty data.
}
hm := MakeGenericHeatmap(data, r.Rand)
for i := hm.NumMutations(); i > 0; i-- {
@@ -410,7 +412,7 @@ func (r *randGen) mutateImage(image []byte) (data []byte, retry bool) {
}
storeInt(data[index:], r.randInt(uint64(width*8)), width)
}
- return Compress(data), false
+ return image.Compress(data), false
}
func mutateBufferSize(r *randGen, arg *DataArg, minLen, maxLen uint64) {