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

Prevent integer overflow in NodeManager and LeafManager #1794

Conversation

ghurstunither
Copy link
Contributor

For large enough grids, leafCounts in initLeafArray() and nodeCounts in initNodeChildren() can overflow as std::vector<Index32>.

Prevent integer overflow on grids with many nodes or leafs.

Signed-off-by: ghurstunither <[email protected]>
@ghurstunither ghurstunither requested a review from kmuseth as a code owner April 16, 2024 17:46
Copy link
Contributor

@danrbailey danrbailey left a comment

Choose a reason for hiding this comment

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

Needs a change for the log and would be ideal if we could add a simple unit test that exceeds 32-bit integer.

@ghurstunither
Copy link
Contributor Author

Needs a change for the log

Is that something I add in this PR?

would be ideal if we could add a simple unit test that exceeds 32-bit integer.

I'm not sure how to do that without making a gigantic tree.

@danrbailey
Copy link
Contributor

I think there's actually more to talk about here. The Tree and RootNode also make assumptions that the number of leaf nodes cannot exceed 2^32:

https://github.com/AcademySoftwareFoundation/openvdb/blob/master/openvdb/openvdb/tree/Tree.h#L116

The tree ones in particular are actually virtual functions, so if we want to bump this arbitrary limit, we should also change those methods as an ABI change.

@ghurstunither
Copy link
Contributor Author

I think there's actually more to talk about here. The Tree and RootNode also make assumptions that the number of leaf nodes cannot exceed 2^32:

https://github.com/AcademySoftwareFoundation/openvdb/blob/master/openvdb/openvdb/tree/Tree.h#L116

The tree ones in particular are actually virtual functions, so if we want to bump this arbitrary limit, we should also change those methods as an ABI change.

Thanks for pointing this out. I think the following should return Index64:

  • unallocatedLeafCount
  • leafCount
  • nodeCount

The other methods seem fine to return Index32 if we assume we'll never exceed 2^32 for other nodes, which I think is reasonable.

leafCount, unallocatedLeafCount, nodeCount now work with Index64 to accommodate trees with more than 2^32-1 leaf nodes.

Signed-off-by: ghurstunither <[email protected]>
@ghurstunither ghurstunither requested a review from Idclip as a code owner October 24, 2024 16:12
Correct type for variable.

Signed-off-by: ghurstunither <[email protected]>
Turns off OPENVDB_BUILD_UNITTESTS.

Signed-off-by: ghurstunither <[email protected]>
Use Index64 for tree's leafCount.

Signed-off-by: ghurstunither <[email protected]>
Correct type for nodeCount members.

Signed-off-by: ghurstunither <[email protected]>
* nonLeafCount and treeDepth return Index64 in TreeBase.
* All ABI breakages safeguarded for versions < 12.
* Deprecated implementations of nodeCount for vector<Index32> arguments.

Signed-off-by: ghurstunither <[email protected]>
Restore 32 bit functionality for versions below 12.

Signed-off-by: ghurstunither <[email protected]>
Prevent nodeCount deprecation warnings.

Signed-off-by: ghurstunither <[email protected]>
Backward compatibility for unit tests.

Signed-off-by: ghurstunither <[email protected]>
trailing space

Signed-off-by: ghurstunither <[email protected]>
AX tests for correct leafCount return type.

Signed-off-by: ghurstunither <[email protected]>
trailing space

Signed-off-by: ghurstunither <[email protected]>
AX test failures

Signed-off-by: ghurstunither <[email protected]>
deprecation suppression in recursive nodeCount calls.

Signed-off-by: ghurstunither <[email protected]>
openvdb/openvdb/tree/Tree.h Outdated Show resolved Hide resolved
openvdb/openvdb/tree/InternalNode.h Outdated Show resolved Hide resolved
openvdb/openvdb/tree/InternalNode.h Outdated Show resolved Hide resolved
define deprecated nodeCount for all versions.

Signed-off-by: ghurstunither <[email protected]>
Keep Index return type for treeDepth.

Signed-off-by: ghurstunither <[email protected]>
Avoid ABI conditionals in Root/Internal/Leaf node files.

Signed-off-by: ghurstunither <[email protected]>
Copy link
Contributor

@danrbailey danrbailey left a comment

Choose a reason for hiding this comment

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

Just one small diffing error to resolve, otherwise this all looks good to me, thanks for making all those changes!

openvdb/openvdb/unittest/TestTree.cc Outdated Show resolved Hide resolved
Remove migrated tests.

Signed-off-by: ghurstunither <[email protected]>
@danrbailey danrbailey merged commit c484949 into AcademySoftwareFoundation:master Oct 30, 2024
40 checks passed
@ghurstunither ghurstunither deleted the bugfix/NodeManager_overflow branch October 30, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants