summaryrefslogtreecommitdiff
path: root/ext/zip/lib/zip_add_entry.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/zip/lib/zip_add_entry.c')
-rw-r--r--ext/zip/lib/zip_add_entry.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/ext/zip/lib/zip_add_entry.c b/ext/zip/lib/zip_add_entry.c
index 24dbdaf47c..9a9465c5f0 100644
--- a/ext/zip/lib/zip_add_entry.c
+++ b/ext/zip/lib/zip_add_entry.c
@@ -1,6 +1,6 @@
/*
zip_add_entry.c -- create and init struct zip_entry
- Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner
+ Copyright (C) 1999-2015 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
@@ -46,8 +46,19 @@ _zip_add_entry(zip_t *za)
if (za->nentry+1 >= za->nentry_alloc) {
zip_entry_t *rentries;
- zip_uint64_t nalloc = za->nentry_alloc + 16;
- zip_uint64_t realloc_size = sizeof(struct zip_entry) * (size_t)nalloc;
+ zip_uint64_t nalloc = za->nentry_alloc;
+ zip_uint64_t additional_entries = 2 * nalloc;
+ zip_uint64_t realloc_size;
+
+ if (additional_entries < 16) {
+ additional_entries = 16;
+ }
+ else if (additional_entries > 1024) {
+ additional_entries = 1024;
+ }
+ /* neither + nor * overflows can happen: nentry_alloc * sizeof(struct zip_entry) < UINT64_MAX */
+ nalloc += additional_entries;
+ realloc_size = sizeof(struct zip_entry) * (size_t)nalloc;
if (sizeof(struct zip_entry) * (size_t)za->nentry_alloc > realloc_size) {
zip_error_set(&za->error, ZIP_ER_MEMORY, 0);