fd/replay: Clamp dumped wrbuf to buffer size
We should be careful to not read past the end of any buffers when dumping wrbufs, this clamps the size to the size of the buffer with a warning. Signed-off-by: Mark Collins <mark@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28253>
This commit is contained in:
@@ -384,8 +384,16 @@ device_dump_wrbuf(struct device *dev)
|
||||
fprintf(stderr, "Error getting buffer for %s\n", buffer_path);
|
||||
goto end_it;
|
||||
}
|
||||
const void *buffer = buf->map + (wrbuf->iova - buf->iova);
|
||||
fwrite(buffer, wrbuf->size, 1, f);
|
||||
|
||||
uint64_t offset = wrbuf->iova - buf->iova;
|
||||
uint64_t size = MIN2(wrbuf->size, buf->size - offset);
|
||||
if (size != wrbuf->size) {
|
||||
fprintf(stderr, "Warning: Clamping buffer %s as it's smaller than expected (0x%lx < 0x%lx)\n", wrbuf->name, size, wrbuf->size);
|
||||
}
|
||||
|
||||
printf("Dumping %s (0x%lx - 0x%lx)\n", wrbuf->name, wrbuf->iova, wrbuf->iova + size);
|
||||
|
||||
fwrite(buf->map + offset, size, 1, f);
|
||||
|
||||
end_it:
|
||||
fclose(f);
|
||||
|
||||
Reference in New Issue
Block a user