Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve sjson package fuzzing #3071

Merged
merged 5 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
apply linter suggestions
  • Loading branch information
quasilyte committed Jul 18, 2023
commit 4886d1a7d51dcc0bf6212a0be7512d512ae9cec5
7 changes: 5 additions & 2 deletions internal/handlers/sjson/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ var arrayTestCases = []testCase{
name: "array10",
v: convertArray(must.NotFail(types.NewArray(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))),
sch: &elem{
Type: elemTypeArray,
Items: []*elem{doubleSchema, doubleSchema, doubleSchema, doubleSchema, doubleSchema, doubleSchema, doubleSchema, doubleSchema, doubleSchema, doubleSchema},
Type: elemTypeArray,
Items: []*elem{
doubleSchema, doubleSchema, doubleSchema, doubleSchema, doubleSchema,
doubleSchema, doubleSchema, doubleSchema, doubleSchema, doubleSchema,
},
},
j: `[0,1.0,2,3.0,4.0,5.0,6,7,8,9]`,
canonJ: `[0,1,2,3,4,5,6,7,8,9]`,
Expand Down
7 changes: 7 additions & 0 deletions internal/handlers/sjson/sjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ func isValidDocumentData(v sjsontype) bool {
"_id", "dummy_id",
"value", fromSJSON(v),
))

return d.ValidateData() == nil
}

Expand Down Expand Up @@ -230,11 +231,13 @@ func addRecordedFuzzDocs(f *testing.F, needDocument, needSchema bool) int {
}

args := make([]any, 0, 2)

if needDocument {
j, err := MarshalSingleValue(doc)
require.NoError(f, err)
args = append(args, j)
}

if needSchema {
sch, err := marshalSchemaForDoc(doc)
require.NoError(f, err)
Expand All @@ -255,6 +258,7 @@ func fuzzJSONWithFixedDocuments(f *testing.F, testCases []testCase, newFunc func
j string
}
documents := make([]documentTest, 0, len(testCases))

for _, tc := range testCases {
if tc.jErr != "" || tc.v == nil {
continue
Expand Down Expand Up @@ -299,10 +303,13 @@ func fuzzJSONWithFixedDocuments(f *testing.F, testCases []testCase, newFunc func

func fuzzJSONWithFixedSchemas(f *testing.F, testCases []testCase, newFunc func() sjsontype) {
schemas := make([]string, 0, len(testCases))

for _, tc := range testCases {
sch := must.NotFail(json.Marshal(tc.sch))
schemas = append(schemas, string(sch))

f.Add(tc.j)

if tc.canonJ != "" {
f.Add(tc.canonJ)
}
Expand Down