Author: manx
Date: Fri Mar 15 13:09:56 2024
New Revision: 20349
URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20349
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.29/ (props changed)
branches/OpenMPT-1.29/common/mptIO.cpp
Modified: branches/OpenMPT-1.29/common/mptIO.cpp
==============================================================================
--- branches/OpenMPT-1.29/common/mptIO.cpp Fri Mar 15 13:07:05 2024 (r20348)
+++ branches/OpenMPT-1.29/common/mptIO.cpp Fri Mar 15 13:09:56 2024 (r20349)
@@ -401,16 +401,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(std::byte *dst, IFileDataContainer::off_t pos, IFileDataContainer::off_t count) const
|