llvmpipe: Check for negative size before mapping the memory

CID: 1596479 Argument cannot be negative
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35091>
This commit is contained in:
Corentin Noël
2025-05-21 12:05:00 +02:00
committed by Marge Bot
parent 94f2d53586
commit 383684596c
@@ -1491,6 +1491,12 @@ llvmpipe_import_memory_fd(struct pipe_screen *screen,
#if defined(HAVE_LIBDRM) && defined(HAVE_LINUX_UDMABUF_H)
if (dmabuf) {
off_t mmap_size = lseek(fd, 0, SEEK_END);
if (mmap_size < 0) {
free(alloc);
*ptr = NULL;
return false;
}
lseek(fd, 0, SEEK_SET);
void *cpu_addr = mmap(0, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (cpu_addr == MAP_FAILED) {