From 65765798d85258c0358b28b90aac68ed1851f49b Mon Sep 17 00:00:00 2001 From: DLL125 <134442578+DLL125@users.noreply.github.com> Date: Mon, 17 Jul 2023 14:11:12 +0200 Subject: Libzip (#1152) * Update LZMA to latest * Update Libzip Libzip updated to latest. --- src/Common/libzip/zip_buffer.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/Common/libzip/zip_buffer.c') diff --git a/src/Common/libzip/zip_buffer.c b/src/Common/libzip/zip_buffer.c index a353ce06..e2103f04 100644 --- a/src/Common/libzip/zip_buffer.c +++ b/src/Common/libzip/zip_buffer.c @@ -132,13 +132,20 @@ _zip_buffer_left(zip_buffer_t *buffer) { zip_uint64_t _zip_buffer_read(zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length) { + zip_uint64_t copied; + if (_zip_buffer_left(buffer) < length) { length = _zip_buffer_left(buffer); } - memcpy(data, _zip_buffer_get(buffer, length), length); + copied = 0; + while (copied < length) { + size_t n = ZIP_MIN(length - copied, SIZE_MAX); + (void)memcpy_s(data + copied, n, _zip_buffer_get(buffer, n), n); + copied += n; + } - return length; + return copied; } @@ -147,8 +154,14 @@ _zip_buffer_new(zip_uint8_t *data, zip_uint64_t size) { bool free_data = (data == NULL); zip_buffer_t *buffer; +#if ZIP_UINT64_MAX > SIZE_MAX + if (size > SIZE_MAX) { + return NULL; + } +#endif + if (data == NULL) { - if ((data = (zip_uint8_t *)malloc(size)) == NULL) { + if ((data = (zip_uint8_t *)malloc((size_t)size)) == NULL) { return NULL; } } @@ -221,7 +234,7 @@ _zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length) { return -1; } - memcpy(dst, src, length); + (void)memcpy_s(dst, length, src, length); return 0; } -- cgit v1.2.3