avcodec/hashtable: Check for overflow
Reviewed-by: Emma Worley <emma@emma.gg> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
1e6fdafce0
commit
2e45d2f7d3
1 changed files with 7 additions and 1 deletions
|
|
@ -56,12 +56,18 @@ struct FFHashtableContext {
|
|||
|
||||
int ff_hashtable_alloc(struct FFHashtableContext **ctx, size_t key_size, size_t val_size, size_t max_entries)
|
||||
{
|
||||
const size_t keyval_size = key_size + val_size;
|
||||
|
||||
if (keyval_size < key_size || // did (unsigned,defined) wraparound happen?
|
||||
keyval_size > SIZE_MAX - sizeof(size_t) - (ALIGN - 1))
|
||||
return AVERROR(ERANGE);
|
||||
|
||||
FFHashtableContext *res = av_mallocz(sizeof(*res));
|
||||
if (!res)
|
||||
return AVERROR(ENOMEM);
|
||||
res->key_size = key_size;
|
||||
res->val_size = val_size;
|
||||
res->entry_size = FFALIGN(sizeof(size_t) + key_size + val_size, ALIGN);
|
||||
res->entry_size = FFALIGN(sizeof(size_t) + keyval_size, ALIGN);
|
||||
res->max_entries = max_entries;
|
||||
res->nb_entries = 0;
|
||||
res->crc = av_crc_get_table(AV_CRC_32_IEEE);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue