VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/libzip/zip_buffer.c
diff options
context:
space:
mode:
authorDLL125 <134442578+DLL125@users.noreply.github.com>2023-07-17 14:11:12 +0200
committerGitHub <noreply@github.com>2023-07-17 14:11:12 +0200
commit65765798d85258c0358b28b90aac68ed1851f49b (patch)
tree22f573edc4e16790d9be208fce95db1134fe2ba4 /src/Common/libzip/zip_buffer.c
parent6267b91931af87db2b95172389a6fbaac206e42e (diff)
downloadVeraCrypt-65765798d85258c0358b28b90aac68ed1851f49b.tar.gz
VeraCrypt-65765798d85258c0358b28b90aac68ed1851f49b.zip
Libzip (#1152)
* Update LZMA to latest * Update Libzip Libzip updated to latest.
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;
}