mirror of
https://github.com/isledecomp/SIEdit.git
synced 2024-11-27 01:25:45 -05:00
file: prevent out of bounds reads with memory buffer
This commit is contained in:
parent
70e97e88c0
commit
c2456a489e
1 changed files with 9 additions and 4 deletions
13
lib/file.cpp
13
lib/file.cpp
|
@ -283,20 +283,25 @@ void MemoryBuffer::seek(File::pos_t p, SeekMode s)
|
|||
{
|
||||
switch (s) {
|
||||
case SeekStart:
|
||||
m_Position = p;
|
||||
m_Position = std::min(p, size());
|
||||
break;
|
||||
case SeekCurrent:
|
||||
m_Position += p;
|
||||
m_Position = std::min(m_Position + p, size());
|
||||
break;
|
||||
case SeekEnd:
|
||||
m_Position = std::max(pos_t(0), pos_t(m_Internal.size() - p));
|
||||
if (p > size()) {
|
||||
m_Position = 0;
|
||||
} else {
|
||||
m_Position = size() - p;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
File::pos_t MemoryBuffer::ReadData(void *data, File::pos_t size)
|
||||
{
|
||||
size = std::min(size, m_Internal.size() - m_Position);
|
||||
pos_t remaining = m_Internal.size() - m_Position;
|
||||
size = std::min(size, remaining);
|
||||
memcpy(data, m_Internal.data() + m_Position, size);
|
||||
m_Position += size;
|
||||
return size;
|
||||
|
|
Loading…
Reference in a new issue