-
Notifications
You must be signed in to change notification settings - Fork 43
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 #210
Comments
Please rerun with |
Thanks for the update! The misalignment here makes me wonder whether the passed in material itself is dead or incorrect. Is there a repository where I can run this code with a debugger attached? @rlidwka CC :-) |
@tgolsson, can you maybe spot anything that can cause this error in the following physx-rs/physx/src/traits/user_data.rs Lines 26 to 32 in 60827dd
This is a spurious error. It failed at the first material being created, only on one machine, The line it fails at is here: Be aware that that branch uses older physx-rs version that works with physx4 (because bindings for vehicles from physx5 don't exist yet), but relevant code in physx-rs hasn't changed since then. If you want, you can run |
gonna debug it later today |
I'm really confused to be honest. Either the write is misaligned, or the read is... |
Ok, as usual, the problem is apparent after refuting it. The read must be the problem (if the material is valid). We're reading an 8 byte word from a location containing 1 byte. And reading those bytes together enforces the 8-byte alignment. Doesn't matter how we get to the invalid alignment, it's clearly UB. We should probably cast the target instead of the source... writing 1 byte to an 8-byte location is legal. @rlidwka if you have repro, do you care to try switching the cast to the other side and seeing what falls out? |
@tgolsson, on @fgadaleta's machine read seems to have alignment of 1 for the reasons I don't fully understand. The following code works. Is this what you had in mind? unsafe fn init_user_data(&mut self, user_data: Self::UserData) -> &mut Self {
if size_of::<Self::UserData>() > size_of::<*mut c_void>() {
// Too big to pack into a *mut c_void, kick it to the heap.
let data = Box::into_raw(Box::new(user_data));
*(self.user_data_ptr_mut() as *mut *mut c_void as *mut *mut Self::UserData) = data;
} else {
// DATA_SIZE <= VOID_SIZE
*(self.user_data_ptr_mut() as *mut *mut c_void as *mut Self::UserData) = user_data;
}
self
} |
You mean that the pointee has a 1-byte alignment? That's correct given that
Yes, pretty much. The userData is going to be aligned by 8-bytes inside its parent object in every situation, and always 8 bytes big. |
Indeed in |
I have just updated Rustc 1.73 and have the same problem. I have never had it before. The problem is exactly the same - creating a material without user data (so with a unit struct). I am also confused now as to why this has never been a problem before. And what should I do now? Also, why doesn't the example have the same problem? Or does it? I'll check. The example crashes funny:
|
😕 Are you able to repro with the test too? |
Rust added these asserts in debug mode in Rust 1.70 (rust-lang/rust#98112). |
I have always been using the latest Rust and started seeing this issue just now after the upgrade to 1.73. |
By test, what exactly do you mean? |
There's a unit test here: physx-rs/physx/src/traits/user_data.rs Lines 65 to 113 in 1ef3b01
|
This one passes, but another one fails:
Note that the |
This looks like a different issue; cc @Jake-Shadle -- do you recognize it from rewriting the pxbind setup? |
Please note that there are two issues - one is the example of One piece of news: this is probably related to the changes in 1.73. Before the update of Rustc, I had never had this issue. Now, I also have other issues with Vulkan, really-really-really weird ones (my code is plain simple, and I can't use it wrong, besides the fact that since 1.6x and until just 1.73, it has always been working). I suspect a regression in 1.73. UPD: 1.72.1 works okay (in debug), I don't have this issue. Contrary, 1.73, 1.74 and 1.75 have the same behaviour. |
I can repro the issue with |
Interesting, what that might be then? ... 🤔 |
Fixed the If we trust gdb, then there is probably a bit more information on where this misaligned pointer dereference happens:
I guess the problem is that the fix for the issue hasn't been published as a new version of the crate, and I still depend on the version in crates.io instead of this git repository. Will the fix ever be uploaded to crates.io? |
One last update: the problem is actually fixed but hasn't been published to crates.io. I do not see this issue anymore with the changes made to fix it earlier by changing the dependency from crates.io to this git repository. I, however, would like to depend on it through crates.io to avoid some in-between breakages. |
Ah, ok. Closing again! I've wanted to make a release but haven't had the time. Will close this and try to do a release today. |
Sure thing! I apologise for having taken your time, but I didn't know I had been using an outdated version all this time. Thank you! |
Describe the bug
The text was updated successfully, but these errors were encountered: