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

GODRIVER-3451 Add fuzz test for BSON MarshalValue/UnmarshalValue. #1993

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matthewdale
Copy link
Collaborator

GODRIVER-3451

Summary

  • Fuzz bson.MarshalValue and bson.UnmarshalValue.
  • Enable the data race detector during fuzzing

Background & Motivation

@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the priority-3-low Low Priority PR for Review label Mar 21, 2025
Copy link
Contributor

API Change Report

No changes found!

@prestonvasquez
Copy link
Collaborator

@matthewdale Can you re-configure the evergreen tasks to include Fuzz testing?

// int64, including max and min values.
int64(0), math.MaxInt64, math.MinInt64,
// string, including empty and large string.
"", strings.Repeat("z", 10_000),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we extend this to include a nested structure and a slice?

map[string]any{"nested": []any{1, "two", map[string]any{"three", 3}}}
[]any{1, 2,3, "four"}

f.Add(byte(typ), b)
}

f.Fuzz(func(t *testing.T, bsonType byte, data []byte) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK we can run these tests in parallel.

t.Fatalf("failed to marshal: %v", err)
}

if err := UnmarshalValue(typ, encoded, &v); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest decoding into a new value (e.g. var v2 any). Then we can compare the original value and the re-unmarshaled value to ensure roundtrip consistency:

if !reflect.DeepEqual(v, v2) {
	t.Fatal("roundtrip mismatch: ...")
}

// to "nil". It's not clear if MarshalValue should support "nil", but
// for now we skip it.
if v == nil {
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth logging such cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-3-low Low Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants