Browse Source

Fixed a potential crash when reading MIDI files with incorrect track length chunks

tags/2021-05-28
ed 6 years ago
parent
commit
0ed474e412
1 changed files with 5 additions and 4 deletions
  1. +5
    -4
      modules/juce_audio_basics/midi/juce_MidiFile.cpp

+ 5
- 4
modules/juce_audio_basics/midi/juce_MidiFile.cpp View File

@@ -262,25 +262,26 @@ bool MidiFile::readFrom (InputStream& sourceStream, bool createMatchingNoteOffs)
if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
{
size -= (size_t) (d - static_cast<const uint8*> (data.getData()));
int track = 0;
while (size > 0 && track < expectedTracks)
for (;;)
{
auto chunkType = (int) ByteOrder::bigEndianInt (d);
d += 4;
auto chunkSize = (int) ByteOrder::bigEndianInt (d);
d += 4;
if (chunkSize <= 0)
if (chunkSize <= 0 || (size_t) chunkSize > size)
break;
if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
readNextTrack (d, chunkSize, createMatchingNoteOffs);
if (++track >= expectedTracks)
break;
size -= (size_t) chunkSize + 8;
d += chunkSize;
++track;
}
return true;


Loading…
Cancel
Save