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

Indexing cache_table::CacheTable on 32-bit systems may cause overflow #89

Open
Kakusakov opened this issue Nov 1, 2024 · 0 comments
Open

Comments

@Kakusakov
Copy link

let entry = unsafe { *self.table.get_unchecked((hash as usize) & self.mask) };

let e = unsafe { self.table.get_unchecked_mut((hash as usize) & self.mask) };

let e = unsafe { self.table.get_unchecked_mut((hash as usize) & self.mask) };

On 32-bit systems hash as usize will overflow if the value of hash is greater than u32::MAX.

This overflow is mostly harmless in release mode (as the hash will just be truncated to the 32-bit boundary), but it will cause a panic in debug mode.

Replace (hash as usize) & self.mask with (hash & (self.mask as u64)) as usize to prevent overflow.

You may also want to change the type of self.mask to u64

@Kakusakov Kakusakov changed the title indexing cache_table::CacheTable on 32-bit systems may cause overflow Indexing cache_table::CacheTable on 32-bit systems may cause overflow Nov 1, 2024
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