VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/libzip/zip_source_pkware_encode.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2025-01-01 10:37:56 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2025-01-01 10:37:56 +0100
commit138e5e7c1dfba4717a4e6d5abb1abb0f82d6f49f (patch)
treefd6bc3d389d162a9f555a415e410e84cd7988492 /src/Common/libzip/zip_source_pkware_encode.c
parentfcc6302e6139b5b4714c91fd91d215c77af7695c (diff)
downloadVeraCrypt-138e5e7c1dfba4717a4e6d5abb1abb0f82d6f49f.tar.gz
VeraCrypt-138e5e7c1dfba4717a4e6d5abb1abb0f82d6f49f.zip
Windows: Update libzip to version 1.11.2HEADmaster
Diffstat (limited to 'src/Common/libzip/zip_source_pkware_encode.c')
-rw-r--r--src/Common/libzip/zip_source_pkware_encode.c63
1 files changed, 27 insertions, 36 deletions
diff --git a/src/Common/libzip/zip_source_pkware_encode.c b/src/Common/libzip/zip_source_pkware_encode.c
index d89b9f4e..fed76115 100644
--- a/src/Common/libzip/zip_source_pkware_encode.c
+++ b/src/Common/libzip/zip_source_pkware_encode.c
@@ -1,6 +1,6 @@
/*
zip_source_pkware_encode.c -- Traditional PKWARE encryption routines
- Copyright (C) 2009-2020 Dieter Baron and Thomas Klausner
+ Copyright (C) 2009-2024 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <info@libzip.org>
@@ -42,8 +42,7 @@ struct trad_pkware {
zip_pkware_keys_t keys;
zip_buffer_t *buffer;
bool eof;
- bool mtime_set;
- time_t mtime;
+ zip_dostime_t dostime;
zip_error_t error;
};
@@ -52,7 +51,6 @@ static int encrypt_header(zip_source_t *, struct trad_pkware *);
static zip_int64_t pkware_encrypt(zip_source_t *, void *, void *, zip_uint64_t, zip_source_cmd_t);
static void trad_pkware_free(struct trad_pkware *);
static struct trad_pkware *trad_pkware_new(const char *password, zip_error_t *error);
-static void set_mtime(struct trad_pkware* ctx, zip_stat_t* st);
zip_source_t *
zip_source_pkware_encode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flags, const char *password) {
@@ -69,9 +67,24 @@ zip_source_pkware_encode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flag
}
if ((ctx = trad_pkware_new(password, &za->error)) == NULL) {
+ zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
return NULL;
}
+ if (zip_source_get_dos_time(src, &ctx->dostime) <= 0) {
+ zip_stat_t st;
+
+ if (zip_source_stat(src, &st) < 0) {
+ zip_error_set_from_source(&za->error, src);
+ trad_pkware_free(ctx);
+ return NULL;
+ }
+ if (_zip_u2d_time((st.valid & ZIP_STAT_MTIME) ? st.mtime : time(NULL), &ctx->dostime, &za->error) < 0) {
+ trad_pkware_free(ctx);
+ return NULL;
+ }
+ }
+
if ((s2 = zip_source_layered(za, src, pkware_encrypt, ctx)) == NULL) {
trad_pkware_free(ctx);
return NULL;
@@ -83,20 +96,8 @@ zip_source_pkware_encode(zip_t *za, zip_source_t *src, zip_uint16_t em, int flag
static int
encrypt_header(zip_source_t *src, struct trad_pkware *ctx) {
- unsigned short dostime, dosdate;
zip_uint8_t *header;
- if (!ctx->mtime_set) {
- struct zip_stat st;
- if (zip_source_stat(src, &st) != 0) {
- zip_error_set_from_source(&ctx->error, src);
- return -1;
- }
- set_mtime(ctx, &st);
- }
-
- _zip_u2d_time(ctx->mtime, &dostime, &dosdate);
-
if ((ctx->buffer = _zip_buffer_new(NULL, ZIP_CRYPTO_PKWARE_HEADERLEN)) == NULL) {
zip_error_set(&ctx->error, ZIP_ER_MEMORY, 0);
return -1;
@@ -112,7 +113,7 @@ encrypt_header(zip_source_t *src, struct trad_pkware *ctx) {
ctx->buffer = NULL;
return -1;
}
- header[ZIP_CRYPTO_PKWARE_HEADERLEN - 1] = (zip_uint8_t)((dostime >> 8) & 0xff);
+ header[ZIP_CRYPTO_PKWARE_HEADERLEN - 1] = (zip_uint8_t)((ctx->dostime.time >> 8) & 0xff);
_zip_pkware_encrypt(&ctx->keys, header, header, ZIP_CRYPTO_PKWARE_HEADERLEN);
@@ -187,9 +188,6 @@ pkware_encrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t length, zip
if (st->valid & ZIP_STAT_COMP_SIZE) {
st->comp_size += ZIP_CRYPTO_PKWARE_HEADERLEN;
}
- set_mtime(ctx, st);
- st->mtime = ctx->mtime;
- st->valid |= ZIP_STAT_MTIME;
return 0;
}
@@ -206,8 +204,16 @@ pkware_encrypt(zip_source_t *src, void *ud, void *data, zip_uint64_t length, zip
return 0;
}
+ case ZIP_SOURCE_GET_DOS_TIME:
+ if (length < sizeof(ctx->dostime)) {
+ zip_error_set(&ctx->error, ZIP_ER_INVAL, 0);
+ return -1;
+ }
+ (void)memcpy_s(data, sizeof(ctx->dostime), &ctx->dostime, sizeof(ctx->dostime));
+ return sizeof(ctx->dostime);
+
case ZIP_SOURCE_SUPPORTS:
- return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_GET_FILE_ATTRIBUTES, -1);
+ return zip_source_make_command_bitmap(ZIP_SOURCE_OPEN, ZIP_SOURCE_READ, ZIP_SOURCE_CLOSE, ZIP_SOURCE_STAT, ZIP_SOURCE_ERROR, ZIP_SOURCE_FREE, ZIP_SOURCE_GET_FILE_ATTRIBUTES, ZIP_SOURCE_GET_DOS_TIME, -1);
case ZIP_SOURCE_ERROR:
return zip_error_to_data(&ctx->error, data, length);
@@ -237,8 +243,6 @@ trad_pkware_new(const char *password, zip_error_t *error) {
return NULL;
}
ctx->buffer = NULL;
- ctx->mtime_set = false;
- ctx->mtime = 0;
zip_error_init(&ctx->error);
return ctx;
@@ -256,16 +260,3 @@ trad_pkware_free(struct trad_pkware *ctx) {
zip_error_fini(&ctx->error);
free(ctx);
}
-
-
-static void set_mtime(struct trad_pkware* ctx, zip_stat_t* st) {
- if (!ctx->mtime_set) {
- if (st->valid & ZIP_STAT_MTIME) {
- ctx->mtime = st->mtime;
- }
- else {
- time(&ctx->mtime);
- }
- ctx->mtime_set = true;
- }
-}