Author: sagamusix
Date: Thu Mar 14 20:36:46 2024
New Revision: 20322
URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20322
Log:
[Fix] DMF: Avoid pretending that we want to read 4GB worth of data. This can cause a crash when libopenmpt is used with unseekable streams, in particular in 32-bit builds. Directly request FileReader::BytesLeft() bytes to be read, which we normally avoid because it causes the whole file to be pre-cached - which is what we end up doing here anyway (https://www.un4seen.com/forum/?topic=15448.msg142533#msg142533).
Modified:
trunk/OpenMPT/soundlib/Load_dmf.cpp
Modified: trunk/OpenMPT/soundlib/Load_dmf.cpp
==============================================================================
--- trunk/OpenMPT/soundlib/Load_dmf.cpp Thu Mar 14 08:06:18 2024 (r20321)
+++ trunk/OpenMPT/soundlib/Load_dmf.cpp Thu Mar 14 20:36:46 2024 (r20322)
@@ -934,7 +934,7 @@
// I don't know when exactly this stopped, but I have no version 5-7 files to check (and no X-Tracker version that writes those versions).
// Since this is practically always the last chunk in the file, the following code is safe for those versions, though.
else if(fileHeader.version < 8 && chunkHeader.GetID() == DMFChunk::idSMPD)
- chunkLength = uint32_max;
+ chunkLength = mpt::saturate_cast<uint32>(file.BytesLeft());
chunks.chunks.push_back(ChunkReader::Item<DMFChunk>{chunkHeader, file.ReadChunk(chunkLength)});
file.Skip(chunkSkip);
}
|