Author: manx
Date: Fri Mar 15 12:39:15 2024
New Revision: 20335
URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20335
Log:
[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:
trunk/OpenMPT/src/mpt/io_read/filedata_base_unseekable.hpp
Modified: trunk/OpenMPT/src/mpt/io_read/filedata_base_unseekable.hpp
==============================================================================
--- trunk/OpenMPT/src/mpt/io_read/filedata_base_unseekable.hpp Fri Mar 15 11:44:54 2024 (r20334)
+++ trunk/OpenMPT/src/mpt/io_read/filedata_base_unseekable.hpp Fri Mar 15 12:39:15 2024 (r20335)
@@ -86,15 +86,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:
|