pulse: also handle potential overflow in ROUND_UP

This commit is contained in:
Wim Taymans 2026-05-14 16:27:20 +02:00
parent af151b088d
commit 79b4aba6cc

View file

@ -379,6 +379,7 @@ done:
static int ensure_size(struct message *m, uint32_t size) static int ensure_size(struct message *m, uint32_t size)
{ {
uint64_t needed;
uint32_t alloc, diff; uint32_t alloc, diff;
void *data; void *data;
@ -388,10 +389,10 @@ static int ensure_size(struct message *m, uint32_t size)
if (size <= m->allocated - m->length) if (size <= m->allocated - m->length)
return size; return size;
if (m->allocated + size < m->allocated) needed = SPA_ROUND_UP_N(SPA_MAX((uint64_t)m->allocated + size, 4096u), 4096u);
if (needed > UINT32_MAX)
return -ENOMEM; return -ENOMEM;
alloc = (uint32_t)needed;
alloc = SPA_ROUND_UP_N(SPA_MAX(m->allocated + size, 4096u), 4096u);
diff = alloc - m->allocated; diff = alloc - m->allocated;
if ((data = realloc(m->data, alloc)) == NULL) { if ((data = realloc(m->data, alloc)) == NULL) {
free(m->data); free(m->data);