mirror of
https://github.com/vbatts/tar-split.git
synced 2025-02-17 23:07:51 +00:00
tar/asm: try out a go-fuzz test
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
4de2011f4a
commit
8c5af0ccf2
1 changed files with 38 additions and 0 deletions
38
tar/asm/fuzz.go
Normal file
38
tar/asm/fuzz.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
// +build gofuzz
|
||||
|
||||
package asm
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
|
||||
"github.com/vbatts/tar-split/archive/tar"
|
||||
"github.com/vbatts/tar-split/tar/storage"
|
||||
)
|
||||
|
||||
func Fuzz(data []byte) int {
|
||||
sp := storage.NewJSONPacker(bytes.NewBuffer([]byte{}))
|
||||
fgp := storage.NewBufferFileGetPutter()
|
||||
tarStream, err := NewInputTarStream(bytes.NewReader(data), sp, fgp)
|
||||
if err != nil {
|
||||
if tarStream != nil {
|
||||
panic("tarStream is != nil on error")
|
||||
}
|
||||
log.Println(err)
|
||||
return 0
|
||||
}
|
||||
rdr := tar.NewReader(tarStream)
|
||||
|
||||
for {
|
||||
hdr, err := rdr.Next()
|
||||
if err != nil {
|
||||
if hdr != nil {
|
||||
panic("hdr is != nil on error")
|
||||
}
|
||||
log.Println(err)
|
||||
return 0
|
||||
}
|
||||
log.Printf("%v", hdr)
|
||||
}
|
||||
return 1
|
||||
}
|
Loading…
Reference in a new issue