Skip to content

Commit

Permalink
fix: enable fuzz tests and fix decoder bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Feb 19, 2024
1 parent 66bd218 commit b8b37f1
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions dev/decoder/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (d *structDecoder) FromDom(vp unsafe.Pointer, node internal.Node, ctx *cont
var gerr error
obj, err := node.AsObj()
if err != nil {
return nil
return err
}

next := obj.Children()
Expand All @@ -36,7 +36,7 @@ func (d *structDecoder) FromDom(vp unsafe.Pointer, node internal.Node, ctx *cont
val := internal.NewNode(internal.PtrOffset(next, 1))
next = val.Next()
if err != nil {
return nil
return err
}

idx := d.fieldMap.TryGet(key, i)
Expand Down
4 changes: 2 additions & 2 deletions dev/internal/sonic_rs.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (node *Node) AsMapEface(ctx *Context, vp unsafe.Pointer) error {
func (node *Node) AsMapEfaceUseNumber(ctx *Context, vp unsafe.Pointer) error {
obj, err := node.AsObj()
if err != nil {
return nil
return err
}

size := obj.Len()
Expand Down Expand Up @@ -517,7 +517,7 @@ func (node *Node) AsMapEfaceUseNumber(ctx *Context, vp unsafe.Pointer) error {
func (node *Node) AsMapEfaceUseInt64(ctx *Context, vp unsafe.Pointer) error {
obj, err := node.AsObj()
if err != nil {
return nil
return err
}

size := obj.Len()
Expand Down
2 changes: 1 addition & 1 deletion dev/rs_wrapper/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dev/rs_wrapper/lib/darwin/libsonic_rs_aarch64-apple-darwin.a
Binary file not shown.
Binary file modified dev/rs_wrapper/lib/darwin/libsonic_rs_x86_64-apple-darwin.a
Binary file not shown.
Binary file modified dev/rs_wrapper/lib/linux/libsonic_rs_aarch64-unknown-linux-gnu.a
Binary file not shown.
Binary file modified dev/rs_wrapper/lib/linux/libsonic_rs_x86_64-unknown-linux-gnu.a
Binary file not shown.
36 changes: 19 additions & 17 deletions fuzz/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.18
// +build go1.18

/*
Expand All @@ -19,21 +20,21 @@
package sonic_fuzz

import (
`encoding/json`
`testing`
_ `unicode/utf8`
`os`
`runtime`
`runtime/debug`
`time`
`io`
`log`
`strconv`

`github.com/bytedance/sonic`
`github.com/stretchr/testify/require`
`github.com/davecgh/go-spew/spew`
`github.com/bytedance/gopkg/util/gctuner`
"encoding/json"
"io"
"log"
"os"
"runtime"
"runtime/debug"
"strconv"
"testing"
"time"
"unicode/utf8"

"github.com/bytedance/gopkg/util/gctuner"
"github.com/bytedance/sonic"
"github.com/davecgh/go-spew/spew"
"github.com/stretchr/testify/require"
)

func FuzzMain(f *testing.F) {
Expand All @@ -57,8 +58,9 @@ func fuzzMain(t *testing.T, data []byte) {
fuzzHtmlEscape(t, data)
// fuzz ast get api, should not panic here.
fuzzAst(t, data)
// Only fuzz the validate json here.
if !json.Valid(data) {
// Rust std repr invalid utf8 chars is diff from Golang,
// so we skip invalid utf8 here.
if !json.Valid(data) || !utf8.Valid(data) {
return
}
fuzzStream(t, data)
Expand Down

0 comments on commit b8b37f1

Please sign in to comment.