Skip to content

Commit

Permalink
Fix crash after reading a MIDICustomMetaEvent with payload size > 127…
Browse files Browse the repository at this point in the history
… bytes (#2892)

* Fix crash after reading a MIDICustomMetaEvent with payload size > 127 byte.
MetaEvents start with a byte with value FF, then a byte containing the meta event type, then a variable count of n bytes containing the encoded length of payload and finally the payload.
The old assumes the value 1 instead of n for the count of bytes containing the length of payload.
Changed code uses the count of bytes from vlqLength.length.

* Fix comment spacing violation reported by hound bot

---------

Co-authored-by: Matthias Bauer <[email protected]>
  • Loading branch information
techfreak01 and Matthias Bauer committed Feb 23, 2024
1 parent e58f4aa commit c5db1e4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/AudioKit/MIDI/Enums/MIDICustomMetaEvent.swift
Expand Up @@ -125,7 +125,7 @@ public struct MIDICustomMetaEvent: MIDIMessage {
let type = MIDICustomMetaEventType(rawValue: data[1]),
let vlqLength = MIDIVariableLengthQuantity(fromBytes: Array(data.suffix(from: 2))) {
self.length = Int(vlqLength.quantity)
self.data = Array(data.prefix(3 + length)) //drop excess data
self.data = Array(data.prefix(2 + vlqLength.length + length)) // drop excess data
self.type = type
} else {
return nil
Expand Down

0 comments on commit c5db1e4

Please sign in to comment.