Fix overflow when clamping length of buffer data fetch

This commit is contained in:
baldurk
2020-03-20 16:16:51 +00:00
parent a7af387a36
commit 839c510a75
4 changed files with 14 additions and 18 deletions
+1 -1
View File
@@ -351,7 +351,7 @@ void D3D11DebugManager::GetBufferData(ID3D11Buffer *buffer, uint64_t offset, uin
return;
}
if(len == 0)
if(len == 0 || len > desc.ByteWidth)
{
len = desc.ByteWidth - offs;
}
+1 -1
View File
@@ -819,7 +819,7 @@ void D3D12DebugManager::GetBufferData(ID3D12Resource *buffer, uint64_t offset, u
return;
}
if(length == 0)
if(length == 0 || length > desc.Width)
{
length = desc.Width - offset;
}
+11 -15
View File
@@ -323,27 +323,23 @@ void GLReplay::GetBufferData(ResourceId buff, uint64_t offset, uint64_t len, byt
uint64_t bufsize = buf.size;
if(len > 0 && offset + len > bufsize)
if(offset >= bufsize)
{
RDCWARN("Attempting to read off the end of the buffer (%llu %llu). Will be clamped (%llu)",
offset, len, bufsize);
if(offset < bufsize)
len = ~0ULL; // min below will clamp to max size
else
return; // offset past buffer size, return empty array
// can't read past the end of the buffer, return empty
return;
}
else if(len == 0)
if(len == 0 || len > bufsize)
{
len = bufsize;
}
// need to ensure len+offset doesn't overrun buffer or the glGetBufferSubData call
// will fail.
len = RDCMIN(len, bufsize - offset);
if(len == 0)
return;
if(offset + len > bufsize)
{
RDCWARN("Attempting to read off the end of the buffer (%llu %llu). Will be clamped (%llu)",
offset, len, bufsize);
len = RDCMIN(len, bufsize - offset);
}
ret.resize((size_t)len);
+1 -1
View File
@@ -1573,7 +1573,7 @@ void VulkanDebugManager::GetBufferData(ResourceId buff, uint64_t offset, uint64_
return;
}
if(len == 0)
if(len == 0 || len > bufsize)
{
len = bufsize - offset;
}