Skip to content

Commit f4ef239

Browse files
committed
The check for the chunk size must happen before any data is read to avoid invalid memory reads on empty files.
1 parent 1db606b commit f4ef239

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/load_psm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ BOOL CSoundFile::ReadPSM(LPCBYTE lpStream, DWORD dwMemLength)
105105
BYTE samplemap[MAX_SAMPLES];
106106
UINT nPatterns;
107107

108+
if (dwMemLength < 256) return FALSE;
109+
108110
// Swap chunk
109111
swap_PSMCHUNK(pfh);
110112

111113
// Chunk0: "PSM ",filesize,"FILE"
112-
if (dwMemLength < 256) return FALSE;
113114
if (pfh->id == PSM_ID_OLD)
114115
{
115116
#ifdef PSM_LOG

0 commit comments

Comments
 (0)