Add missing sanity checks

This commit is contained in:
Clownacy 2020-07-08 01:02:56 +01:00
parent a015d4d02e
commit 82a6160a31

View file

@ -88,6 +88,7 @@ BOOL InitSoundObject(const char *resname, int no)
unsigned short format = resource_pointer[5] | (resource_pointer[6] << 8);
unsigned short channels = resource_pointer[7] | (resource_pointer[8] << 8);
unsigned long sample_rate = resource_pointer[9] | (resource_pointer[0xA] << 8) | (resource_pointer[0xB] << 16) | (resource_pointer[0xC] << 24);
unsigned short bits_per_sample = resource_pointer[0x13] | (resource_pointer[0x14] << 8);
if (format != 1) // 1 is WAVE_FORMAT_PCM
return FALSE;
@ -95,6 +96,9 @@ BOOL InitSoundObject(const char *resname, int no)
if (channels != 1) // The mixer only supports mono right now
return FALSE;
if (bits_per_sample != 8) // The mixer only supports 8-bit samples (unsigned ones, at that)
return FALSE;
// 二次バッファの生成 (Create secondary buffer)
lpSECONDARYBUFFER[no] = AudioBackend_CreateSound(sample_rate, resource_pointer + 0x3A, buffer_size);
@ -156,6 +160,7 @@ BOOL LoadSoundObject(const char *file_name, int no)
unsigned short format = wp[5] | (wp[6] << 8);
unsigned short channels = wp[7] | (wp[8] << 8);
unsigned long sample_rate = wp[9] | (wp[0xA] << 8) | (wp[0xB] << 16) | (wp[0xC] << 24);
unsigned short bits_per_sample = wp[0x13] | (wp[0x14] << 8);
if (format != 1) // 1 is WAVE_FORMAT_PCM
{
@ -169,6 +174,12 @@ BOOL LoadSoundObject(const char *file_name, int no)
return FALSE;
}
if (bits_per_sample != 8) // The mixer only supports 8-bit samples (unsigned ones, at that)
{
free(wp);
return FALSE;
}
// セカンダリバッファの生成 (Create secondary buffer)
lpSECONDARYBUFFER[no] = AudioBackend_CreateSound(sample_rate, wp + 0x3A, buffer_size);