Skip to content

Commit

Permalink
Merged revision(s) 20335 from trunk/OpenMPT:
Browse files Browse the repository at this point in the history
[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.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@20340 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
manxorist committed Mar 15, 2024
1 parent 1cf2df4 commit 87c8b63
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/mpt/io_read/filedata_base_unseekable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,14 @@ class FileDataUnseekable : public IFileData {
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:
Expand Down

0 comments on commit 87c8b63

Please sign in to comment.