Skip LIST chunks in WAV files in Unix wxSound implementation

Ignore chunks having informational data instead of failing to load WAV
files containing them.

Closes #23859.
This commit is contained in:
A. Jiang 2023-09-08 20:46:37 +08:00 committed by Vadim Zeitlin
parent 4844d37df1
commit 5c86933fd3

View file

@ -660,7 +660,20 @@ bool wxSound::LoadWAV(const void* data_, size_t length, bool copyData)
if (waveformat.uiSize != 16)
return false;
if (memcmp(&data[FMT_INDEX + waveformat.uiSize + 8], "data", 4) != 0)
// Skip the "LIST" chunk if present.
wxUint32 data_offset = FMT_INDEX + waveformat.uiSize + 8;
if (memcmp(&data[data_offset], "LIST", 4) == 0)
{
wxUint32 list_chunk_length;
memcpy(&list_chunk_length, &data[data_offset + 4], 4);
list_chunk_length = wxUINT32_SWAP_ON_BE(list_chunk_length);
if (length - (data_offset + 8u) < list_chunk_length)
return false;
data_offset += (list_chunk_length + 8u);
}
if (memcmp(&data[data_offset], "data", 4) != 0)
return false;
if (waveformat.uiFormatTag != WAVE_FORMAT_PCM)
@ -694,7 +707,7 @@ bool wxSound::LoadWAV(const void* data_, size_t length, bool copyData)
// get the sound data size
wxUint32 ul;
memcpy(&ul, &data[FMT_INDEX + waveformat.uiSize + 12], 4);
memcpy(&ul, &data[data_offset + 4u], 4);
ul = wxUINT32_SWAP_ON_BE(ul);
// ensure we actually have at least that much data in the input
@ -716,8 +729,7 @@ bool wxSound::LoadWAV(const void* data_, size_t length, bool copyData)
else
m_data->m_dataWithHeader = const_cast<wxUint8*>(data);
m_data->m_data =
(&m_data->m_dataWithHeader[FMT_INDEX + waveformat.uiSize + 8]);
m_data->m_data = (&m_data->m_dataWithHeader[data_offset]);
return true;
}