Skip to content

Add fuzz test for CellUnion #193

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

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

Add fuzz test for CellUnion #193

wants to merge 1 commit into from

Conversation

panmari
Copy link
Collaborator

@panmari panmari commented Jun 28, 2025

And jointly fixing panic that can happen for bad input. Slice creation with n < 0 panics. Starting point for #175

And jointly fixing panic that can happen for bad input. Slice creation with n < 0 panics.
@@ -553,7 +553,7 @@ func (cu *CellUnion) encode(e *encoder) {
}
}

// Decode decodes the CellUnion.
// Decode decodes the CellUnion. The resulting CellUnion is not check for validity.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo: "is not checked"

Probably clearer to explicitly mentionIsValid though.

@@ -570,7 +570,7 @@ func (cu *CellUnion) decode(d *decoder) {
return
}
n := d.readInt64()
if d.err != nil {
if d.err != nil || n < 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do C++/Java do? Should this be read as uint64 / should the error be updated like below?


func FuzzDecodeCellUnion(f *testing.F) {
cuCells := CellUnion([]CellID{
CellID(0x33),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these cells matter at all? How were they generated?

// Construction failed, no need to test further.
return
}
if got := c.ApproxArea(); got < 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you testing 0 but not 4 pi? What if the union isn't valid?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants