tools: Fix crash can happens on malformed audio wave file

This commit is contained in:
Antoine SOULIER
2022-09-15 13:33:07 -07:00
parent 448f3de31f
commit 8b3720abce

View File

@@ -102,9 +102,12 @@ int wave_read_header(FILE *fp, int *bitdepth, int *samplesize,
return -1; return -1;
if (fread(&format, sizeof(format), 1, fp) != 1 if (fread(&format, sizeof(format), 1, fp) != 1
|| format.id != WAVE_FORMAT_ID || format.id != WAVE_FORMAT_ID
|| format.fmt != WAVE_FORMAT_PCM || format.fmt != WAVE_FORMAT_PCM
|| format.byterate != format.samplerate * format.framesize) || format.channels <= 0
|| format.samplerate <= 0
|| format.framesize <= 0
|| format.byterate != format.samplerate * format.framesize)
return -1; return -1;
fseek(fp, sizeof(format) - (8 + format.size), SEEK_CUR); fseek(fp, sizeof(format) - (8 + format.size), SEEK_CUR);