From d6ebb60f203b0f9cf6b9efe1c6852c93d24b25ff Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 12 Jul 2021 13:40:45 -0700 Subject: [PATCH] vkr: fix temp pool alloc align expects 32-bit integers while size_t can be 64-bit. Also move aligning to after size is checked against VKR_CS_DECODER_TEMP_POOL_MAX_SIZE. Signed-off-by: Chia-I Wu Reviewed-by: Yiwei Zhang --- src/vkr_cs.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/vkr_cs.h b/src/vkr_cs.h index e02e71f..3acb0f8 100644 --- a/src/vkr_cs.h +++ b/src/vkr_cs.h @@ -226,16 +226,19 @@ vkr_cs_decoder_alloc_temp(struct vkr_cs_decoder *dec, size_t size) { struct vkr_cs_decoder_temp_pool *pool = &dec->temp_pool; - /* align to 64-bit */ - size = align(size, 8); if (unlikely(size > (size_t)(pool->end - pool->cur))) { if (!vkr_cs_decoder_alloc_temp_internal(dec, size)) { vkr_cs_decoder_set_fatal(dec); return NULL; } - assert(size <= (size_t)(pool->end - pool->cur)); } + /* align to 64-bit after we know size is at most + * VKR_CS_DECODER_TEMP_POOL_MAX_SIZE and cannot overflow + */ + size = (size + 7) & ~7; + assert(size <= (size_t)(pool->end - pool->cur)); + void *ptr = pool->cur; pool->cur += size; return ptr;