-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for go1.18 fuzzing; fixes
- Loading branch information
Showing
11 changed files
with
141 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package ubjson | ||
|
||
import "fmt" | ||
import "github.com/pkg/errors" | ||
|
||
func errTooMany(len int) error { | ||
return fmt.Errorf("too many calls for container with len %d", len) | ||
return errors.Errorf("too many calls for container with len %d", len) | ||
} | ||
|
||
func errWrongTypeWrite(exp, got Marker) error { | ||
return fmt.Errorf("unable to write type '%s' to container type '%s'", exp, got) | ||
return errors.Errorf("unable to write element type '%s' to container type '%s'", got, exp) | ||
} | ||
|
||
func errWrongTypeRead(exp, got Marker) error { | ||
return fmt.Errorf("tried to read type '%s' but found type '%s'", exp, got) | ||
return errors.Errorf("tried to read type '%s' but found type '%s'", exp, got) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
package ubjson | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package ubjson | ||
|
||
import ( | ||
"embed" | ||
"os" | ||
"testing" | ||
) | ||
|
||
//go:embed testdata/**/* | ||
var testdata embed.FS | ||
|
||
func FuzzBinary(f *testing.F) { | ||
for _, c := range cases { | ||
f.Add(c.binary) | ||
} | ||
const corpus = "testdata/bin/corpus" | ||
if dir, err := testdata.ReadDir(corpus); err != nil { | ||
f.Fatal("failed to read corpus dir:", err) | ||
} else { | ||
for _, c := range dir { | ||
if c.IsDir() { | ||
continue | ||
} | ||
if b, err := os.ReadFile(corpus + "/" + c.Name()); err != nil { | ||
f.Error("failed to open corpus file:", err) | ||
} else { | ||
f.Add(b) | ||
} | ||
} | ||
} | ||
f.Fuzz(func(t *testing.T, data []byte) { | ||
var i interface{} | ||
if Unmarshal(data, &i) != nil { | ||
t.Skip() | ||
} | ||
if _, err := Marshal(i); err != nil { | ||
t.Errorf("failed to re-marshal: %+v\n", err) | ||
t.Logf("original: 0x%x\n", data) | ||
t.Logf("value: %#v\n", i) | ||
bl, err := MarshalBlock(i) | ||
if err != nil { | ||
t.Error("block: failed to marshal:", err) | ||
} else { | ||
t.Log("block:", bl) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
func FuzzBlock(f *testing.F) { | ||
for _, c := range cases { | ||
f.Add(c.block) | ||
} | ||
const corpus = "testdata/block/corpus" | ||
if dir, err := testdata.ReadDir(corpus); err != nil { | ||
f.Fatal("failed to read corpus dir:", err) | ||
} else { | ||
for _, c := range dir { | ||
if c.IsDir() { | ||
continue | ||
} | ||
if b, err := os.ReadFile(corpus + "/" + c.Name()); err != nil { | ||
f.Error("failed to open corpus file:", err) | ||
} else { | ||
f.Add(string(b)) | ||
} | ||
} | ||
} | ||
f.Fuzz(func(t *testing.T, data string) { | ||
var i interface{} | ||
if UnmarshalBlock([]byte(data), &i) != nil { | ||
t.Skip() | ||
} | ||
if _, err := MarshalBlock(i); err != nil { | ||
t.Errorf("failed to re-marshal: %+v\n", err) | ||
t.Log("original:", data) | ||
t.Logf("value: %#v\n", i) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/jmank88/ubjson | ||
|
||
go 1.12 | ||
go 1.18 | ||
|
||
require github.com/pkg/errors v0.8.1 |
2 changes: 2 additions & 0 deletions
2
testdata/fuzz/FuzzBinary/52a8589fb3fbeb9e223a988400f8a0a12f2f1952d87f0bae9e950c94a90fabea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("[$d#U\x190000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") |
2 changes: 2 additions & 0 deletions
2
testdata/fuzz/FuzzBinary/b5ea624f1f6cd506a15f6ca3a5f86c38549135c789b8d97dbbf084d21369685f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("[$C#U\x010") |
2 changes: 2 additions & 0 deletions
2
testdata/fuzz/FuzzBlock/6e80b181765c2b8b7791e98f75c5c8cbd830647bdbba557f2cfa63f6d7b197ca
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
string("[[][$][C][#][U][1][0]") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters