|
From: <sv...@op...> - 2026-10-25 17:27:48
|
Author: sagamusix Date: Sun Oct 25 18:27:41 2026 New Revision: 25814 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=25814 Log: Merged revision(s) 25811-25813 from trunk/OpenMPT: [Fix] WAV: It was possible that a fact chunk claimed an impossibly big sample length for an IMA ADPCM sample, causing unnecessarily large memory allocations. ........ [Fix] WAV: Also sanitize IMA ADPCM sample length for mono samples. ........ [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: branches/OpenMPT-1.32/ (props changed) branches/OpenMPT-1.32/soundlib/WAVTools.cpp Modified: branches/OpenMPT-1.32/soundlib/WAVTools.cpp ============================================================================== --- branches/OpenMPT-1.32/soundlib/WAVTools.cpp Sun Oct 25 18:26:57 2026 (r25813) +++ branches/OpenMPT-1.32/soundlib/WAVTools.cpp Sun Oct 25 18:27:41 2026 (r25814) @@ -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() > 0)) + 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; @@ -124,6 +125,7 @@ sampleLength *= 2; } } + LimitMax(sampleLength, expectedLengthFrames); } if((formatInfo.format != WAVFormatChunk::fmtIMA_ADPCM || sampleLength == 0) && GetSampleSize() != 0) |