8000 crash with large sysex on MacOS · Issue #165 · Boddlnagg/midir · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

crash with large sysex on MacOS #165

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

Open
mzero opened this issue Feb 4, 2025 · 2 comments
Open

crash with large sysex on MacOS #165

mzero opened this issue Feb 4, 2025 · 2 comments

Comments

@mzero
Copy link
mzero commented Feb 4, 2025

While not documented in the coremidi crate, PacketBuffer has an intrinsic size limit based on a poorly documented and handled size limit in Apple's CoreMIDI MIDIPacketList and MIDIPacket structures. The size limit is a bit less than 65536. (Exact value isn't documented!)


MidiOutputConnection's send() takes whatever data is passed in and passes it directly to PacketBuffer. If the data is big (think 80k sysex messages) - then PacketBuffer creates a corrupted buffer, which when sent causes a hard crash.

If the semantics of send() are that it will send what ever it is handed... then it needs to break larger messages up into chunks, and send the one after another.

If the semantics of send() are that it wants to inherit the limits of PacketBuffer, then it should document, and perhaps enforce that constraint.


How did I find this? I'm sending 80k sysexs (to control a synth) from a WebMIDI app.... and in Firefox on Mac it crashes the browser completely and instantly! I don't know who to blame for the crash... but the 80k byte array gets passed:

JavaScript -> Firefox/Gekko's C++ code -> Firefox/Gekkot's Rust crate midir_impl -> Boodlnagg's Rust midir package -> coremidi

@mzero
Copy link
Author
mzero commented Feb 4, 2025

bug filed with FireFox: https://bugzilla.mozilla.org/show_bug.cgi?id=1945967

Also, note, midir's handling of large SysEx on Linux works just fine.

@Boddlnagg
Copy link
Owner
Boddlnagg commented Feb 5, 2025

Thanks for reporting the bug! The underlying reason is that the coremidi crate is unsound. The macOS implementation in midir uses the safe API from coremidi, which is not supposed to crash (it may panic, though ... not sure if that would also crash the Firefox browser). But this should be fixed in coremidi to return a Result::Err in such a case, which would then be forwarded by midir.

You're probably right that the solution of splitting such a large sysex into multiple messages could and should be done in midir, to make the sending of such large messages consistently work on all platforms.
Seems like inspiration could be taken from Chromium. A PR is welcome :-)

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
0