VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/libzip/zip_buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/libzip/zip_buffer.c')
-rw-r--r--src/Common/libzip/zip_buffer.c21
1 files changed, 17 insertions, 4 deletions
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;
}