|
From: <sv...@op...> - 2026-10-25 17:27:04
|
Author: sagamusix Date: Sun Oct 25 18:26:57 2026 New Revision: 25813 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=25813 Log: [Fix] WAV: Avoid sample length claimed by fact chunk to remain unsanitized when other conditions already determine that the IMA ADPCM parameters are invalid. It would still cause memory to be allocated. Modified: trunk/OpenMPT/soundlib/WAVTools.cpp Modified: trunk/OpenMPT/soundlib/WAVTools.cpp ============================================================================== --- trunk/OpenMPT/soundlib/WAVTools.cpp Sun Oct 25 18:04:42 2026 (r25812) +++ trunk/OpenMPT/soundlib/WAVTools.cpp Sun Oct 25 18:26:57 2026 (r25813) @@ -104,11 +104,12 @@ sampleData = chunks.GetChunk(RIFFChunk::idpcm_); } - // "fact" chunk should contain sample length of compressed samples. - sampleLength = chunks.GetChunk(RIFFChunk::idfact).ReadUint32LE(); - - if((formatInfo.format == WAVFormatChunk::fmtIMA_ADPCM) && (GetBlockAlign() > 4 * formatInfo.numChannels)) + sampleLength = 0; + if((formatInfo.format == WAVFormatChunk::fmtIMA_ADPCM) && (GetBlockAlign() >= 4 * formatInfo.numChannels)) { + // "fact" chunk should contain sample length of compressed samples. + sampleLength = chunks.GetChunk(RIFFChunk::idfact).ReadUint32LE(); + FileReader::pos_type dataLength = sampleData.GetLength(); std::size_t blocks = mpt::align_up<FileReader::pos_type>(dataLength, GetBlockAlign()) / GetBlockAlign(); std::size_t framesPerBlock = ((GetBlockAlign() - (4 * formatInfo.numChannels)) * 2 / formatInfo.numChannels) + 1; |