@@ -254,7 +254,7 @@ BOOL CSoundFile::ReadGDM(const BYTE *lpStream, DWORD dwMemLength)
254254 (samplesPos < sizeof (FILEHEADERGDM )) || (samplesPos >= dwMemLength) ||
255255 (samplesPos + sizeof (SAMPLEGDM ) * nSamples > dwMemLength) ||
256256 (sampleDataPos < sizeof (FILEHEADERGDM )) || (sampleDataPos >= dwMemLength))
257- return FALSE ;
257+ return TRUE ;
258258
259259 // Most GDMs were converted from S3M and BWSB generally behaves like an S3M
260260 // player, so assuming S3M behavior and quirks is a fairly safe bet.
@@ -348,7 +348,7 @@ BOOL CSoundFile::ReadGDM(const BYTE *lpStream, DWORD dwMemLength)
348348 UINT rows = 0 ;
349349 UINT channel;
350350
351- if (patEnd > dwMemLength) return FALSE ;
351+ if (patEnd > dwMemLength) break ;
352352
353353 pos += 2 ;
354354 while (pos < patEnd)
@@ -368,7 +368,7 @@ BOOL CSoundFile::ReadGDM(const BYTE *lpStream, DWORD dwMemLength)
368368 // Note and sample.
369369 if (dat & 0x20 )
370370 {
371- if (pos + 2 > patEnd) return FALSE ;
371+ if (pos + 2 > patEnd) break ;
372372 pos += 2 ;
373373 }
374374
@@ -377,7 +377,7 @@ BOOL CSoundFile::ReadGDM(const BYTE *lpStream, DWORD dwMemLength)
377377 {
378378 do
379379 {
380- if (pos + 2 > patEnd) return FALSE ;
380+ if (pos + 2 > patEnd) break ;
381381 dat = lpStream[pos];
382382 pos += 2 ;
383383 } while (dat & 0x20 );
@@ -387,6 +387,9 @@ BOOL CSoundFile::ReadGDM(const BYTE *lpStream, DWORD dwMemLength)
387387
388388 PatternSize[npat] = rows;
389389 }
390+ // Discard truncated/corrupted patterns (if any).
391+ if (npat < nPatterns)
392+ nPatterns = npat;
390393
391394 // Load patterns.
392395 pos = patternsPos;
0 commit comments