aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-12-17 12:12:05 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-12-22 10:11:08 +0100
commita0df376348d2ad1d3e557ea221e75c78a5d9fd96 (patch)
treeb15ead346eb5f9f01e71dca1f4f4d1966da3e0cf /prog
parent09ff16760eac2d6f03e93bd7d50892a6d536ed1b (diff)
pkg/image: make Decompress easier to use
Change DecompressWriter to DecompressCheck: checking validity of the image is the only useful use of DecompressWriter. Change Decompress to MustDecompress which does not return an error. We check validity during program deserialization, so all other uses already panic on errors. Also add dtor return value in preparation for subsequent changes.
Diffstat (limited to 'prog')
-rw-r--r--prog/analysis.go6
-rw-r--r--prog/encoding.go3
-rw-r--r--prog/mutation.go6
3 files changed, 5 insertions, 10 deletions
diff --git a/prog/analysis.go b/prog/analysis.go
index fec43e1bd..850fdb1dd 100644
--- a/prog/analysis.go
+++ b/prog/analysis.go
@@ -356,10 +356,8 @@ func (p *Prog) ForEachAsset(cb func(name string, typ AssetType, r io.Reader)) {
if !ok || a.Type().(*BufferType).Kind != BufferCompressed {
return
}
- data, err := image.Decompress(a.Data())
- if err != nil {
- panic(err)
- }
+ data, dtor := image.MustDecompress(a.Data())
+ defer dtor()
if len(data) == 0 {
return
}
diff --git a/prog/encoding.go b/prog/encoding.go
index bfa80b983..bd2efb836 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -7,7 +7,6 @@ import (
"bytes"
"encoding/hex"
"fmt"
- "io/ioutil"
"reflect"
"strconv"
"strings"
@@ -606,7 +605,7 @@ func (p *parser) parseArgString(t Type, dir Dir) (Arg, error) {
}
// Check compressed data for validity.
if typ.IsCompressed() {
- if err := image.DecompressWriter(ioutil.Discard, data); err != nil {
+ if err := image.DecompressCheck(data); err != nil {
p.strictFailf("invalid compressed data in arg: %v", err)
// In non-strict mode, empty the data slice.
data = image.Compress(nil)
diff --git a/prog/mutation.go b/prog/mutation.go
index 100c47a91..5a38cfa88 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -396,10 +396,8 @@ func (r *randGen) mutateImage(compressed []byte) (data []byte, retry bool) {
// Reconsider when/if we move mutation to the host process.
imageMu.Lock()
defer imageMu.Unlock()
- data, err := image.Decompress(compressed)
- if err != nil {
- panic(fmt.Sprintf("could not decompress data: %v", err))
- }
+ data, dtor := image.MustDecompress(compressed)
+ defer dtor()
if len(data) == 0 {
return compressed, true // Do not mutate empty data.
}