diff options
author | David Robillard <d@drobilla.net> | 2014-12-30 23:07:19 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2014-12-30 23:10:11 -0500 |
commit | 168d1879943859653e197237e9baf57f3feb909e (patch) | |
tree | 220e4537d9e7090c8bab9fac1f1f58cab756951b /libs/evoral/evoral | |
parent | 4facff3b8ea68cf8f90e63e9f41b27349b1a43d6 (diff) |
Load what we can from broken/truncated MIDI files.
We're still a very long way from tolerant of weird SMF files (libsmf takes a
"crash if input is not exactly perfect" philosophy, if we're going to be polite
and elevate such a thing to "philosophy"), but at least we'll get what's there
from files truncated by old broken versions of Ardour or other situations.
Diffstat (limited to 'libs/evoral/evoral')
-rw-r--r-- | libs/evoral/evoral/midi_util.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libs/evoral/evoral/midi_util.h b/libs/evoral/evoral/midi_util.h index 5c72fb86c9..f32e816321 100644 --- a/libs/evoral/evoral/midi_util.h +++ b/libs/evoral/evoral/midi_util.h @@ -95,7 +95,9 @@ midi_event_size(const uint8_t* buffer) int end; for (end = 1; buffer[end] != MIDI_CMD_COMMON_SYSEX_END; end++) { - assert((buffer[end] & 0x80) == 0); + if ((buffer[end] & 0x80) != 0) { + return -1; + } } assert(buffer[end] == MIDI_CMD_COMMON_SYSEX_END); return end + 1; @@ -118,6 +120,11 @@ midi_event_is_valid(const uint8_t* buffer, size_t len) if (size < 0 || (size_t)size != len) { return false; } + for (size_t i = 1; i < len; ++i) { + if ((buffer[i] & 0x80) != 0) { + return false; // Non-status byte has MSb set + } + } return true; } |