Browse Source

Fixed an invalid memory read when handling MIDI reset messages

tags/2021-05-28
Tom Poole 6 years ago
parent
commit
e1e3b42b4f
3 changed files with 32 additions and 18 deletions
  1. +10
    -3
      modules/juce_audio_basics/midi/juce_MidiBuffer.cpp
  2. +10
    -3
      modules/juce_audio_basics/midi/juce_MidiMessage.cpp
  3. +12
    -12
      modules/juce_audio_basics/midi/juce_MidiMessage.h

+ 10
- 3
modules/juce_audio_basics/midi/juce_MidiBuffer.cpp View File

@@ -57,9 +57,16 @@ namespace MidiBufferHelpers
}
else if (byte == 0xff)
{
int n;
const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
size = jmin (maxBytes, n + 2 + bytesLeft);
if (maxBytes == 1)
{
size = 1;
}
else
{
int n;
const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
size = jmin (maxBytes, n + 2 + bytesLeft);
}
}
else if (byte >= 0x80)
{


+ 10
- 3
modules/juce_audio_basics/midi/juce_MidiMessage.cpp View File

@@ -224,9 +224,16 @@ MidiMessage::MidiMessage (const void* srcData, int sz, int& numBytesUsed, const
}
else if (byte == 0xff)
{
int n;
const int bytesLeft = readVariableLengthVal (src + 1, n);
size = jmin (sz + 1, n + 2 + bytesLeft);
if (sz == 1)
{
size = 1;
}
else
{
int n;
const int bytesLeft = readVariableLengthVal (src + 1, n);
size = jmin (sz + 1, n + 2 + bytesLeft);
}
auto dest = allocateSpace (size);
*dest = (uint8) byte;


+ 12
- 12
modules/juce_audio_basics/midi/juce_MidiMessage.h View File

@@ -83,19 +83,19 @@ public:
complete message, and will return the number of bytes it used. This lets
you read a sequence of midi messages from a file or stream.
@param data the data to read from
@param maxBytesToUse the maximum number of bytes it's allowed to read
@param numBytesUsed returns the number of bytes that were actually needed
@param lastStatusByte in a sequence of midi messages, the initial byte
can be dropped from a message if it's the same as the
first byte of the previous message, so this lets you
supply the byte to use if the first byte of the message
has in fact been dropped.
@param timeStamp the time to give the midi message - this value doesn't
use any particular units, so will be application-specific
@param data the data to read from
@param maxBytesToUse the maximum number of bytes it's allowed to read
@param numBytesUsed returns the number of bytes that were actually needed
@param lastStatusByte in a sequence of midi messages, the initial byte
can be dropped from a message if it's the same as the
first byte of the previous message, so this lets you
supply the byte to use if the first byte of the message
has in fact been dropped.
@param timeStamp the time to give the midi message - this value doesn't
use any particular units, so will be application-specific
@param sysexHasEmbeddedLength when reading sysexes, this flag indicates whether
to expect the data to begin with a variable-length field
indicating its size
to expect the data to begin with a variable-length
field indicating its size
*/
MidiMessage (const void* data, int maxBytesToUse,
int& numBytesUsed, uint8 lastStatusByte,


Loading…
Cancel
Save