Skip to content

Commit 0ff58e4

Browse files
committed
Check for a valid status byte in SendMidiMessage from wdmaud2.drv
1 parent 8280193 commit 0ff58e4

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/api/Client/WinMM/MidiSrvPort.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -728,22 +728,32 @@ CMidiPort::SendMidiMessage(UINT32 midiMessage)
728728
byte status = midiMessage & 0x000000FF;
729729
//byte* messagePointer = (byte*)(&midiMessage);
730730

731-
if (MIDI_MESSAGE_IS_ONE_BYTE(status))
731+
// if it's a valid status byte, then figure
732+
// out the actual size of the message. If it's
733+
// not a valid status byte, then we just drop it
734+
if (MIDI_BYTE_IS_STATUS_BYTE(status))
732735
{
733-
messageSize = 1;
734-
}
735-
else if (MIDI_MESSAGE_IS_TWO_BYTES(status))
736-
{
737-
messageSize = 2;
736+
if (MIDI_MESSAGE_IS_ONE_BYTE(status))
737+
{
738+
messageSize = 1;
739+
}
740+
else if (MIDI_MESSAGE_IS_TWO_BYTES(status))
741+
{
742+
messageSize = 2;
743+
}
744+
else if (MIDI_MESSAGE_IS_THREE_BYTES(status))
745+
{
746+
messageSize = 3;
747+
}
748+
749+
// send the message to the transport
750+
// pass a timestamp of 0 to bypass scheduler
751+
RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(&midiMessage, messageSize, 0));
738752
}
739-
else if (MIDI_MESSAGE_IS_THREE_BYTES(status))
753+
else
740754
{
741-
messageSize = 3;
755+
return E_INVALIDARG;
742756
}
743-
744-
// send the message to the transport
745-
// pass a timestamp of 0 to bypass scheduler
746-
RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(&midiMessage, messageSize, 0));
747757
}
748758

749759
return S_OK;
@@ -789,7 +799,8 @@ CMidiPort::SendLongMessage(LPMIDIHDR buffer)
789799
// TODO: based on the buffer length, this message may require chunking into smaller
790800
// pieces to ensure it fits into the cross process queue.
791801
//
792-
RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(buffer->lpData, buffer->dwBytesRecorded, 0));
802+
//RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(buffer->lpData, buffer->dwBytesRecorded, 0));
803+
RETURN_IF_FAILED(m_MidisrvTransport->SendMidiMessage(buffer->lpData, buffer->dwBufferLength, 0));
793804
}
794805

795806
// mark the buffer as completed

0 commit comments

Comments
 (0)