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 index validation #1093

Open
atynagano opened this issue Sep 21, 2023 · 3 comments
Open

Incorrect index validation #1093

atynagano opened this issue Sep 21, 2023 · 3 comments

Comments

@atynagano
Copy link

pub unsafe fn load<T>(&self, byte_index: u32) -> T {
if byte_index + mem::size_of::<T>() as u32 > self.data.len() as u32 {
panic!("Index out of range");
}
buffer_load_intrinsic(self.data, byte_index)
}

if byte_index + mem::size_of::<T>() as u32 > (mem::size_of::<u32> * self.data.len()) as u32

Isn't the right-hand side multiplied by 4 because data is &[u32]?

@Patryk27
Copy link

ByteAddressableBuffer requires for the data to be aligned to 4 bytes, so the current condition is fine IMO; the naming could be better (word_index: u32), but the comment above explains it's inherited from HLSL.

Note that buffer_load_intrinsic() ends up doing 4 * byte_index:

let two = self.constant_u32(DUMMY_SP, 2);

@atynagano
Copy link
Author

So does the left side size_of<T> needs to be divided by 4? Or does size_of returns dword size?

@Patryk27
Copy link

Patryk27 commented Sep 22, 2023

Oh, yeah - I think it should say mem::size_of::<T>() / 4 then 🤔

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

2 participants