From 8cf1164eb60227c7d65d1b6595be4294fe1325a2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 4 May 2026 14:13:09 +0200 Subject: [PATCH] midifile: reject midi files with invalid values >64 tracks will overflow the track array and a division of 0 will cause a division by zero later. --- src/tools/midifile.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/midifile.c b/src/tools/midifile.c index 6bb70f1c0..2bfd9224e 100644 --- a/src/tools/midifile.c +++ b/src/tools/midifile.c @@ -182,6 +182,12 @@ static int open_read(struct midi_file *mf, const char *filename, struct midi_fil if ((res = read_mthd(mf)) < 0) goto exit_close; + if (mf->info.ntracks > SPA_N_ELEMENTS(mf->tracks) || + mf->info.division == 0) { + res = -EINVAL; + goto exit_close; + } + mf->tempo = DEFAULT_TEMPO; mf->tick = 0;