summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-09-08 22:50:59 +0700
committerGitHub <[email protected]>2025-09-08 22:50:59 +0700
commit4a8b8220d94ccf16bbab47eac6340ce8572eb7b4 (patch)
tree28d7d52e3d27b94e3379f9b14d27778ebe90d451
parent059236998ecb24a30daa8262f8d17ccba4ed3f6d (diff)
parent0263cfc01ab63d6799e80cbbf691af1979cf3ab7 (diff)
Merge pull request #3240 from rppicomidi/fix_3239
fix #3239: discard poorly formed packets
-rw-r--r--src/class/midi/midi_host.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/class/midi/midi_host.c b/src/class/midi/midi_host.c
index 50bda1e36..e6ace316c 100644
--- a/src/class/midi/midi_host.c
+++ b/src/class/midi/midi_host.c
@@ -575,6 +575,11 @@ uint32_t tuh_midi_stream_read(uint8_t idx, uint8_t *p_cable_num, uint8_t *p_buff
}
}
}
+ else {
+ // bad packet discard
+ nread = tu_edpt_stream_read(p_midi->daddr, &p_midi->ep_stream.rx, p_midi->stream_read.buffer, 4);
+ continue;
+ }
} else if (status < MIDI_STATUS_SYSEX_START) {
// then it is a channel message either three bytes or two
uint8_t fake_cin = (status & 0xf0) >> 4;
@@ -617,6 +622,11 @@ uint32_t tuh_midi_stream_read(uint8_t idx, uint8_t *p_cable_num, uint8_t *p_buff
bytes_to_add_to_stream = 1;
}
}
+ else {
+ // bad packet discard
+ nread = tu_edpt_stream_read(p_midi->daddr, &p_midi->ep_stream.rx, p_midi->stream_read.buffer, 4);
+ continue;
+ }
for (uint8_t i = 1; i <= bytes_to_add_to_stream; i++) {
*p_buffer++ = p_midi->stream_read.buffer[i];