aboutsummaryrefslogtreecommitdiffstats
path: root/prog/mutation.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-11-22 17:55:02 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-11-23 09:09:39 +0100
commit52fdf57a86cb556640e5ebcc234bc826ff249546 (patch)
tree7dfc694925b4e67369a228d494dec7c55c86bb4c /prog/mutation.go
parent492c0f2d59bd3eb974761c8eb6817c40e03e8f01 (diff)
prog: don't decompress more than 1 image at a time
Diffstat (limited to 'prog/mutation.go')
-rw-r--r--prog/mutation.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/prog/mutation.go b/prog/mutation.go
index 9b17532c7..86114f700 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -9,6 +9,7 @@ import (
"math"
"math/rand"
"sort"
+ "sync"
)
// Maximum length of generated binary blobs inserted into the program.
@@ -382,10 +383,17 @@ func (t *BufferType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []
return
}
+var imageMu sync.Mutex
+
func (r *randGen) mutateImage(image []byte) (data []byte, retry bool) {
if len(image) == 0 {
return image, 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)
if err != nil {
panic(fmt.Sprintf("could not decompress data: %v", err))