ref: 82a6160a315b26a3f55d29597b841b54449ad5ec
parent: a015d4d02e9b09c15442f051df8ac307823196fc
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Jul 7 21:02:56 EDT 2020
Add missing sanity checks
--- a/src/Sound.cpp
+++ b/src/Sound.cpp
@@ -88,6 +88,7 @@
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 @@
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 @@
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
{
@@ -164,6 +169,12 @@
}
if (channels != 1) // The mixer only supports mono right now
+ {
+ free(wp);
+ return FALSE;
+ }
+
+ if (bits_per_sample != 8) // The mixer only supports 8-bit samples (unsigned ones, at that)
{
free(wp);
return FALSE;