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

misaligned pointer dereference in read_next_value #71

Open
shinmao opened this issue Jun 19, 2023 · 0 comments
Open

misaligned pointer dereference in read_next_value #71

shinmao opened this issue Jun 19, 2023 · 0 comments

Comments

@shinmao
Copy link

shinmao commented Jun 19, 2023

Hi, I found some potential unsoundness in safe method read_next_value:

pub fn read_next_value(&mut self) -> Result<(u32, i32)> {
let pos = self.cursor;
self.ensure_primary_table_buffer()?;
let data = if let Some((start_pos, buf)) = self.primary_table_buffer.as_ref() {
let bit_idx = (self.cursor - *start_pos) as usize * self.dictionary.bit_width();
let idx = bit_idx / 8;
let shift = bit_idx % 8;
let data: &u32 = unsafe { std::mem::transmute(&buf[idx]) };
(*data >> shift) & ((1 << self.dictionary.bit_width()) - 1)

In line 184, the code will transmute type of &u8 to &u32 which will create a misaligned pointer, and the pointer is dereferenced in line 185 which will lead to undefined behavior. Is there any test function for read_next_value?

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