...
 
Commits (3)
......@@ -4,18 +4,20 @@ package boar
import (
"github.com/itchio/boar/memfs"
"github.com/itchio/wharf/state"
)
_dummyConsumer := &state.Consumer{}
var _dummyConsumer = &state.Consumer{}
func Fuzz(data []byte) int {
file := memfs.New(data, "data")
_, err := Probe(&ProbeParams{
File: file,
Consumer: dummyConsumer,
})
if err != nil {
panic(err)
params := &ProbeParams{
File: file,
Consumer: _dummyConsumer,
}
return 0
if _, err := Probe(params); err != nil {
return 0
}
return 1
}
package szextractor
import (
"sync"
"github.com/itchio/sevenzip-go/sz"
"github.com/itchio/wharf/state"
)
var _libMutex sync.Mutex
var _lib *sz.Lib
var _libErr error
var _loadOnce sync.Once
func GetLib(consumer *state.Consumer) (*sz.Lib, error) {
_libMutex.Lock()
defer _libMutex.Unlock()
_loadOnce.Do(func() {
_libErr = EnsureDeps(consumer)
if _libErr != nil {
return
}
_lib, _libErr = sz.NewLib()
})
if _libErr != nil {
return nil, _libErr
}
return _lib, nil
}
......@@ -33,7 +33,6 @@ type szExtractor struct {
consumer *state.Consumer
saveConsumer savior.SaveConsumer
lib *sz.Lib
archive *sz.Archive
in *sz.InStream
format string
......@@ -72,16 +71,10 @@ func New(file eos.File, consumer *state.Consumer) (SzExtractor, error) {
se.free()
})
err := EnsureDeps(consumer)
if err != nil {
return nil, errors.Wrap(err, "ensuring 7-zip deps")
}
lib, err := sz.NewLib()
lib, err := GetLib(consumer)
if err != nil {
return nil, errors.Wrap(err, "opening 7-zip library")
}
se.lib = lib
stats, err := file.Stat()
if err != nil {
......@@ -425,11 +418,6 @@ func (se *szExtractor) free() {
se.in = nil
}
if se.lib != nil {
se.lib.Free()
se.lib = nil
}
se.freed = true
}
......