Skip to content

Commit 87fff4a

Browse files
authored
Merge pull request #68 from sezero/fix-mid
fix short file check to midi loader after commit f0b1b4e - ensure miditracks matches current midiformat - earlier aborting on too-short midi files
2 parents 82fc715 + 3c222f9 commit 87fff4a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/load_mid.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,11 @@ BOOL CSoundFile::TestMID(const BYTE *lpStream, DWORD dwMemLength)
783783
char id[5];
784784
MIDHANDLE h;
785785
MMFILE mm;
786+
if (dwMemLength < 14) return FALSE;
786787
mm.mm = (char *)lpStream;
787788
mm.sz = dwMemLength;
788789
mm.err = 0;
789790
h.mmf = &mm;
790-
if (h.mmf->sz < 8) return FALSE;
791791
mmfseek(h.mmf,0,SEEK_SET);
792792
mmreadSBYTES(id, 4, h.mmf);
793793
id[4] = '\0';
@@ -1224,15 +1224,13 @@ BOOL CSoundFile::ReadMID(const BYTE *lpStream, DWORD dwMemLength)
12241224
pat_init_patnames();
12251225

12261226
mmfseek(h->mmf,8,SEEK_SET);
1227-
if (h->mmf->pos < dwMemLength - 6) {
1228-
h->midiformat = mid_read_short(h);
1229-
h->miditracks = mid_read_short(h);
1230-
h->resolution = mid_read_short(h);
1231-
if( h->midiformat == 0 ) h->miditracks = 1;
1232-
}
1227+
h->midiformat = mid_read_short(h);
1228+
h->miditracks = mid_read_short(h);
1229+
h->resolution = mid_read_short(h);
12331230
if (mm.err) goto ErrorCleanup;
12341231

12351232
// at this point the h->mmf is positioned at first miditrack
1233+
if( h->midiformat == 0 ) h->miditracks = 1;
12361234
if( h->resolution & 0x8000 )
12371235
h->divider = ((h->resolution & 0x7f00)>>8)*(h->resolution & 0xff);
12381236
else

0 commit comments

Comments
 (0)