History

avcodec/hashtable: Check for overflow

Andreas Rheinhardt committed 1 year ago

Commit 2e45d2f1 parent 1e6fdaf1 file · +7 −1Browse files

Unified · Split

libavcodec/hashtable.c+7−1
@@ -56,12 +56,18 @@ struct FFHashtableContext { · 55 unmodified lines
5656
5757 int ff_hashtable_alloc(struct FFHashtableContext **ctx, size_t key_size, size_t val_size, size_t max_entries)
5858 {
59+ const size_t keyval_size = key_size + val_size;
60+
61+ if (keyval_size < key_size || // did (unsigned,defined) wraparound happen?
62+ keyval_size > SIZE_MAX - sizeof(size_t) - (ALIGN - 1))
63+ return AVERROR(ERANGE);
64+
5965 FFHashtableContext *res = av_mallocz(sizeof(*res));
6066 if (!res)
6167 return AVERROR(ENOMEM);
6268 res->key_size = key_size;
6369 res->val_size = val_size;
64− res->entry_size = FFALIGN(sizeof(size_t) + key_size + val_size, ALIGN);
70+ res->entry_size = FFALIGN(sizeof(size_t) + keyval_size, ALIGN);
6571 res->max_entries = max_entries;
6672 res->nb_entries = 0;
6773 res->crc = av_crc_get_table(AV_CRC_32_IEEE);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t