Skip to content

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

@ivan-r-sigaev

Description

@ivan-r-sigaev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions