From 240e5eb9e5dca81b5d3961c9088ede80dbfc8d99 Mon Sep 17 00:00:00 2001 From: negativeExponent <54053706+negativeExponent@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:08:29 +0800 Subject: [PATCH] winmm_midi: Fix midi_write_long_event unable to send sysex correctly (#16804) data size has to be DWORD aligned. Fix https://github.com/libretro/RetroArch/issues/16790 review before merge for confirmation/corrections: @LibretroAdmin @zoltanvb and others --- midi/drivers/winmm_midi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/midi/drivers/winmm_midi.c b/midi/drivers/winmm_midi.c index 0643626dfc..0d4dbba6a0 100644 --- a/midi/drivers/winmm_midi.c +++ b/midi/drivers/winmm_midi.c @@ -343,6 +343,9 @@ static bool winmm_midi_write_long_event(winmm_midi_buffer_t *buf, { DWORD i = buf->header.dwBytesRecorded / sizeof(DWORD); + /* data size has to be DWORD aligned */ + data_size = (data_size + (sizeof(DWORD) - 1)) & ~(sizeof(DWORD) - 1); + if (buf->header.dwBytesRecorded + sizeof(DWORD) * 3 + data_size > sizeof(DWORD) * WINMM_MIDI_BUF_LEN) return false;