-
Notifications
You must be signed in to change notification settings - Fork 20
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
error in PacketListIterator::next
#49
Comments
Same bug here, fixed it by adding #[inline]
pub unsafe fn MIDIPacketNext(pkt: *const MIDIPacket) -> *const MIDIPacket {
// Get pointer to potentially unaligned data without triggering undefined behavior
// addr_of does not require creating an intermediate reference to unaligned data.
let ptrx = ptr::addr_of!((*pkt).data) as *const u8;
let rawl = ptr::addr_of!((*pkt).length) as *const u16;
let offset = rawl.read_unaligned() as isize;
if cfg!(any(target_arch = "arm", target_arch = "aarch64")) {
// MIDIPacket must be 4-byte aligned on ARM
((ptrx.offset(offset + 3) as usize) & !(3usize)) as *const MIDIPacket
} else {
ptrx.offset(offset) as *const MIDIPacket
}
}
#[inline]
pub unsafe fn MIDIEventPacketNext(pkt: *const MIDIEventPacket) -> *const MIDIEventPacket {
// Get pointer to potentially unaligned data without triggering undefined behavi
// or
// addr_of does not require creating an intermediate reference to unaligned data.
let ptrx = ptr::addr_of!((*pkt).words) as *const u8;
let rawwc = ptr::addr_of!((*pkt).wordCount) as *const u32;
let wc = rawwc.read_unaligned() as usize;
let offset = (wc * mem::size_of::<u32>()) as isize;
if cfg!(any(target_arch = "arm", target_arch = "aarch64")) {
// MIDIEventPacket must be 4-byte aligned on ARM
((ptrx.offset(offset + 3) as usize) & !(3usize)) as *const MIDIEventPacket
} else {
ptrx.offset(offset) as *const MIDIEventPacket
}
} Take this as a hack without any warranty ("it works for me"), i have no knowledge of the internals used here... |
This has repeatedly hit users of |
Actually I'm not sure whether that fix is correct. |
Okay, I think the problem is this: "The alignment requirements of MIDIPacket may differ between CPU architectures. On Intel and PowerPC, MIDIPacket is unaligned. On ARM, MIDIPacket must be 4-byte aligned." So I'm assuming that this issue occurs on Intel processors? That would make sense because then Rust sees an unaligned Furthermore, this can only affect |
@jmbarbier @arteme @oilcake Can you confirm that you're seeing this on Intel processors? |
Yep, my one is intel. |
This should be fixed with the latest version of |
Just checked - still panicking on my side with the same error :( |
I think, @Boddlnagg means coremidi-sys version 3.1.1 released a couple hours ago. Unfortunately I no longer have my MS-1 device to check with, so I can be of little help. |
Yes, that's right |
Sorry, did not get it. |
@oilcake So does that mean that it works now? |
Sorry, I just did not still figure out how to check - when I do |
Since neither
If that doesn't work, you can try
|
Thank you so much! I am new to rust and did not know cargo can do such a thing. |
@chris-zen Maybe you can increase the version requirement of |
Hi,
In pod-ui I'm using
coremidi
throughmidir
. I have a badly-behaving M-Vave MS-1 bluetooth MIDI device that keeps crashing the app. I know,midir
0.9.x uses an old version ofcoremidi
, I've tried Boddlnagg/midir#139 and Boddlnagg/midir#142, but the error still prevails.I understand that MS-1 is the culprit here, but is there some sanity-checking in
PacketListIterator
that can be done to prevent crashing?Here are the backtraces:
coremidi-panic-midir0.9.1.txt
coremidi-panic-midir0.9.2+coremidi0.7.0.txt
coremidi-panic-midir0.9.2+coremidi0.8.0.txt
The text was updated successfully, but these errors were encountered: