From: <sv...@op...> - 2024-03-15 12:14:48
|
Author: manx Date: Fri Mar 15 13:14:36 2024 New Revision: 20353 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20353 Log: Merged revision(s) 20349 from branches/OpenMPT-1.29: 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.28/ (props changed) branches/OpenMPT-1.28/common/mptIO.cpp Modified: branches/OpenMPT-1.28/common/mptIO.cpp ============================================================================== --- branches/OpenMPT-1.28/common/mptIO.cpp Fri Mar 15 13:14:11 2024 (r20352) +++ branches/OpenMPT-1.28/common/mptIO.cpp Fri Mar 15 13:14:36 2024 (r20353) @@ -475,16 +475,16 @@ return; } std::size_t alignedpos = Util::SaturateAlignUp<std::size_t>(target, QUANTUM_SIZE); - std::size_t needcount = alignedpos - cachesize; - EnsureCacheBuffer(needcount); - std::size_t readcount = InternalRead(&cache[cachesize], alignedpos - cachesize); - cachesize += readcount; - if(!InternalEof()) + while(!InternalEof() && (cachesize < alignedpos)) { - // can read further - return; + EnsureCacheBuffer(BUFFER_SIZE); + std::size_t readcount = InternalRead(&cache[cachesize], BUFFER_SIZE); + cachesize += readcount; + } + if(InternalEof()) + { + streamFullyCached = true; } - streamFullyCached = true; } void FileDataContainerUnseekable::ReadCached(mpt::byte *dst, IFileDataContainer::off_t pos, IFileDataContainer::off_t count) const |