VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/libzip/zip_algorithm_xz.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_algorithm_xz.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_algorithm_xz.c')
-rw-r--r--src/Common/libzip/zip_algorithm_xz.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/Common/libzip/zip_algorithm_xz.c b/src/Common/libzip/zip_algorithm_xz.c
index d8f4266a..d7a7142d 100644
--- a/src/Common/libzip/zip_algorithm_xz.c
+++ b/src/Common/libzip/zip_algorithm_xz.c
@@ -104,7 +104,7 @@ maximum_compressed_size(zip_uint64_t uncompressed_size) {
static void *
-allocate(bool compress, int compression_flags, zip_error_t *error, zip_uint16_t method) {
+allocate(bool compress, zip_uint32_t compression_flags, zip_error_t *error, zip_uint16_t method) {
struct ctx *ctx;
if ((ctx = (struct ctx *)malloc(sizeof(*ctx))) == NULL) {
@@ -114,16 +114,16 @@ allocate(bool compress, int compression_flags, zip_error_t *error, zip_uint16_t
ctx->error = error;
ctx->compress = compress;
- if (compression_flags < 0 || compression_flags > 9) {
- ctx->compression_flags = 6; /* default value */
+ if (compression_flags <= 9) {
+ ctx->compression_flags = compression_flags;
} else {
- ctx->compression_flags = (zip_uint32_t)compression_flags;
+ ctx->compression_flags = 6; /* default value */
}
ctx->compression_flags |= LZMA_PRESET_EXTREME;
ctx->end_of_input = false;
memset(ctx->header, 0, sizeof(ctx->header));
ctx->header_bytes_offset = 0;
- if (ZIP_CM_LZMA) {
+ if (method == ZIP_CM_LZMA) {
ctx->header_state = INCOMPLETE;
}
else {
@@ -136,13 +136,13 @@ allocate(bool compress, int compression_flags, zip_error_t *error, zip_uint16_t
static void *
-compress_allocate(zip_uint16_t method, int compression_flags, zip_error_t *error) {
+compress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
return allocate(true, compression_flags, error, method);
}
static void *
-decompress_allocate(zip_uint16_t method, int compression_flags, zip_error_t *error) {
+decompress_allocate(zip_uint16_t method, zip_uint32_t compression_flags, zip_error_t *error) {
return allocate(false, compression_flags, error, method);
}
@@ -258,7 +258,7 @@ input(void *ud, zip_uint8_t *data, zip_uint64_t length) {
if (ctx->method == ZIP_CM_LZMA && !ctx->compress && ctx->header_state == INCOMPLETE) {
/* if not, get more of the data */
zip_uint8_t got = (zip_uint8_t)ZIP_MIN(HEADER_BYTES_ZIP - ctx->header_bytes_offset, length);
- memcpy(ctx->header + ctx->header_bytes_offset, data, got);
+ (void)memcpy_s(ctx->header + ctx->header_bytes_offset, sizeof(ctx->header) - ctx->header_bytes_offset, data, got);
ctx->header_bytes_offset += got;
length -= got;
data += got;
@@ -313,6 +313,7 @@ end_of_input(void *ud) {
static zip_compression_status_t
process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
struct ctx *ctx = (struct ctx *)ud;
+ uInt avail_out;
lzma_ret ret;
/* for compression of LZMA1 */
if (ctx->method == ZIP_CM_LZMA && ctx->compress) {
@@ -335,7 +336,7 @@ process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
if (ctx->header_state == OUTPUT) {
/* write header */
zip_uint8_t write_len = (zip_uint8_t)ZIP_MIN(HEADER_BYTES_ZIP - ctx->header_bytes_offset, *length);
- memcpy(data, ctx->header + ctx->header_bytes_offset, write_len);
+ (void)memcpy_s(data, *length, ctx->header + ctx->header_bytes_offset, write_len);
ctx->header_bytes_offset += write_len;
*length = write_len;
if (ctx->header_bytes_offset == HEADER_BYTES_ZIP) {
@@ -345,11 +346,12 @@ process(void *ud, zip_uint8_t *data, zip_uint64_t *length) {
}
}
- ctx->zstr.avail_out = (uInt)ZIP_MIN(UINT_MAX, *length);
+ avail_out = (uInt)ZIP_MIN(UINT_MAX, *length);
+ ctx->zstr.avail_out = avail_out;
ctx->zstr.next_out = (Bytef *)data;
ret = lzma_code(&ctx->zstr, ctx->end_of_input ? LZMA_FINISH : LZMA_RUN);
- *length = *length - ctx->zstr.avail_out;
+ *length = avail_out - ctx->zstr.avail_out;
switch (ret) {
case LZMA_OK: