File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -506,7 +506,8 @@ impl TrackEvent {
506
506
let p = time_offset + len_offset + 1 ;
507
507
ctx. is_smf_sysex = true ;
508
508
let ( event, event_len) = SystemExclusiveMsg :: from_midi ( & v[ p..] , ctx) ?;
509
- if event_len != len as usize {
509
+ // event_length does not include the terminating 0xF7 byte, while len is the length of the entire message
510
+ if event_len != len as usize + 1 {
510
511
return Err ( ParseError :: Invalid ( "Invalid system exclusive message" ) ) ;
511
512
}
512
513
Ok ( (
@@ -515,7 +516,7 @@ impl TrackEvent {
515
516
event : MidiMsg :: SystemExclusive { msg : event } ,
516
517
beat_or_frame,
517
518
} ,
518
- p + event_len ,
519
+ p + len as usize ,
519
520
) )
520
521
}
521
522
0x7 => {
@@ -524,7 +525,7 @@ impl TrackEvent {
524
525
ctx. is_smf_sysex = false ;
525
526
let ( event, event_len) = MidiMsg :: from_midi_with_context ( & v[ p..] , ctx) ?;
526
527
527
- if event_len != len as usize {
528
+ if event_len != len as usize + 1 {
528
529
return Err ( ParseError :: Invalid ( "Invalid system exclusive message" ) ) ;
529
530
}
530
531
Ok ( (
@@ -533,7 +534,7 @@ impl TrackEvent {
533
534
event,
534
535
beat_or_frame,
535
536
} ,
536
- p + event_len ,
537
+ p + len as usize ,
537
538
) )
538
539
}
539
540
0xF => {
Original file line number Diff line number Diff line change @@ -330,3 +330,12 @@ fn test_score_file() {
330
330
assert ! ( deserialize_result. is_ok( ) ) ;
331
331
assert_eq ! ( deserialize_result. unwrap( ) , expected) ;
332
332
}
333
+
334
+ #[ test]
335
+ #[ cfg( feature = "file" ) ]
336
+ fn test_smf_file_with_sysex ( ) {
337
+ let test_file = include_bytes ! ( "./breaking-the-law.mid" ) ;
338
+
339
+ let deserialize_result = MidiFile :: from_midi ( test_file) ;
340
+ assert ! ( deserialize_result. is_ok( ) ) ;
341
+ }
You can’t perform that action at this time.
0 commit comments