summaryrefslogtreecommitdiff
path: root/libavutil/mem.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2013-04-25 00:27:46 +0200
committerStefano Sabatini <stefasab@gmail.com>2013-05-08 01:39:12 +0200
commitee9794ed20528c2aa4c53cf67cb218bdce6e0485 (patch)
tree72180c5e92de0d748d2b828438d745c04c93fb4c /libavutil/mem.c
parentc773adee3fda94e943ead1292330d25b28e10deb (diff)
lavu/mem: fix potential int overflow and crash in av_dynarray_add()
Also extend documentation accordingly.
Diffstat (limited to 'libavutil/mem.c')
-rw-r--r--libavutil/mem.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/libavutil/mem.c b/libavutil/mem.c
index cfa4cbd57a..03bf2c8607 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -249,15 +249,25 @@ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
nb = *nb_ptr;
tab = *(intptr_t**)tab_ptr;
if ((nb & (nb - 1)) == 0) {
- if (nb == 0)
+ if (nb == 0) {
nb_alloc = 1;
- else
+ } else {
+ if (nb > INT_MAX / (2 * sizeof(intptr_t)))
+ goto fail;
nb_alloc = nb * 2;
+ }
tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));
+ if (!tab)
+ goto fail;
*(intptr_t**)tab_ptr = tab;
}
tab[nb++] = (intptr_t)elem;
*nb_ptr = nb;
+ return;
+
+fail:
+ av_freep(tab_ptr);
+ *nb_ptr = 0;
}
static void fill16(uint8_t *dst, int len)