Make sure glGetBufferSubData call doesn't overrun buffer size

This commit is contained in:
baldurk
2014-11-30 20:16:33 +00:00
parent 3fa9dcdf47
commit 5ae4b0d649
+8 -2
View File
@@ -274,17 +274,23 @@ vector<byte> GLReplay::GetBufferData(ResourceId buff, uint32_t offset, uint32_t
}
auto &buf = m_pDriver->m_Buffers[buff];
uint32_t bufsize = (uint32_t)buf.size;
if(len > 0 && offset+len > buf.size)
{
RDCWARN("Attempting to read off the end of the array. Will be clamped");
len = RDCMIN(len, uint32_t(buf.size-offset));
len = ~0U; // min below will clamp to max size size
}
else if(len == 0)
{
len = (uint32_t)buf.size;
len = bufsize;
}
// need to ensure len+offset doesn't overrun buffer or the glGetBufferSubData call
// will fail.
len = RDCMIN(len, bufsize-offset);
ret.resize(len);
WrappedOpenGL &gl = *m_pDriver;