aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/image/compression_nonoptimized.go
blob: 333b468153c209fb9549e8e35a35a6e6b043bd10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright 2022 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

//go:build windows || 386 || arm

package image

import (
	"bytes"
	"sync"
)

var decompressMu sync.Mutex

func mustDecompress(compressed []byte) (data []byte, dtor func()) {
	// 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.
	decompressMu.Lock()
	buf := new(bytes.Buffer)
	if err := decompressWriter(buf, compressed); err != nil {
		panic(err)
	}
	return buf.Bytes(), decompressMu.Unlock
}