From: <sv...@op...> - 2024-03-15 11:44:28
|
Author: manx Date: Fri Mar 15 12:44:11 2024 New Revision: 20340 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20340 Log: Merged revision(s) 20335 from trunk/OpenMPT: [Fix] mpt/io_read/filedata_base_unseekable.hpp: Avoid memory denial-of-service when trying to read way more data than the actual file size from unseekable files. ........ Modified: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/src/mpt/io_read/filedata_base_unseekable.hpp Modified: branches/OpenMPT-1.31/src/mpt/io_read/filedata_base_unseekable.hpp ============================================================================== --- branches/OpenMPT-1.31/src/mpt/io_read/filedata_base_unseekable.hpp Fri Mar 15 12:43:37 2024 (r20339) +++ branches/OpenMPT-1.31/src/mpt/io_read/filedata_base_unseekable.hpp Fri Mar 15 12:44:11 2024 (r20340) @@ -87,15 +87,14 @@ return; } std::size_t alignedpos = mpt::saturate_align_up<std::size_t>(target, QUANTUM_SIZE); - std::size_t needcount = alignedpos - cachesize; - EnsureCacheBuffer(needcount); - std::size_t readcount = InternalReadUnseekable(mpt::span(&cache[cachesize], alignedpos - cachesize)).size(); - cachesize += readcount; - if (!InternalEof()) { - // can read further - return; + while (!InternalEof() && (cachesize < alignedpos)) { + EnsureCacheBuffer(BUFFER_SIZE); + std::size_t readcount = InternalReadUnseekable(mpt::span(&cache[cachesize], BUFFER_SIZE)).size(); + cachesize += readcount; + } + if (InternalEof()) { + streamFullyCached = true; } - streamFullyCached = true; } private: |