Skip to content

Commit 3b4ff0f

Browse files
committed
Detect multiplication overflow in avifArrayCreate
Detect whether (size_t)arr->elementSize * arr->capacity would overflow.
1 parent f0c6d7f commit 3b4ff0f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/utils.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <assert.h>
77
#include <math.h>
8+
#include <stdint.h>
89
#include <string.h>
910

1011
float avifRoundf(float v)
@@ -89,6 +90,11 @@ avifBool avifArrayCreate(void * arrayStruct, uint32_t elementSize, uint32_t init
8990
arr->elementSize = elementSize ? elementSize : 1;
9091
arr->count = 0;
9192
arr->capacity = initialCapacity;
93+
if (arr->capacity > SIZE_MAX / arr->elementSize) {
94+
arr->ptr = NULL;
95+
arr->capacity = 0;
96+
return AVIF_FALSE;
97+
}
9298
size_t byteCount = (size_t)arr->elementSize * arr->capacity;
9399
arr->ptr = (uint8_t *)avifAlloc(byteCount);
94100
if (!arr->ptr) {

0 commit comments

Comments
 (0)