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

incorrect tree_depth #32

Open
themighty1 opened this issue Jun 5, 2023 · 0 comments
Open

incorrect tree_depth #32

themighty1 opened this issue Jun 5, 2023 · 0 comments

Comments

@themighty1
Copy link
Contributor

currently tree depth is incorrectly calculated for power-of-two leaf count. it is +1 than what it should be.

pub fn tree_depth(leaves_count: usize) -> usize {
    8 * core::mem::size_of::<usize>() - leaves_count.leading_zeros() as usize
}

e.g. for leaves_count == 4 this will return 3, whereas it should be 2.

This bug doesn't seem to open any exploitable vectors, it only causes to allocate memory for a non-existent layer.
It is still a good idea to fix this.

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

No branches or pull requests

1 participant