aboutsummaryrefslogtreecommitdiff
path: root/libarchive/archive_read_support_format_zip.c
diff options
context:
space:
mode:
authorMartin Matuska <mm@FreeBSD.org>2025-05-20 10:43:26 +0000
committerMartin Matuska <mm@FreeBSD.org>2025-05-20 10:47:29 +0000
commitb0ea71a8555c0b726319dc2a618cc6d17a4fa4f1 (patch)
tree60869b82df91a12e982719b5b22de99cef0adcef /libarchive/archive_read_support_format_zip.c
parenteff4ff4791c83686dfc7251c9ab3fe8ab9e60f0e (diff)
Diffstat (limited to 'libarchive/archive_read_support_format_zip.c')
-rw-r--r--libarchive/archive_read_support_format_zip.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/libarchive/archive_read_support_format_zip.c b/libarchive/archive_read_support_format_zip.c
index 3e62533bf2d9..daf51933d687 100644
--- a/libarchive/archive_read_support_format_zip.c
+++ b/libarchive/archive_read_support_format_zip.c
@@ -71,6 +71,7 @@
#include "archive_private.h"
#include "archive_rb.h"
#include "archive_read_private.h"
+#include "archive_time_private.h"
#include "archive_ppmd8_private.h"
#ifndef HAVE_ZLIB_H
@@ -465,27 +466,6 @@ compression_name(const int compression)
return "??";
}
-/* Convert an MSDOS-style date/time into Unix-style time. */
-static time_t
-zip_time(const char *p)
-{
- int msTime, msDate;
- struct tm ts;
-
- msTime = (0xff & (unsigned)p[0]) + 256 * (0xff & (unsigned)p[1]);
- msDate = (0xff & (unsigned)p[2]) + 256 * (0xff & (unsigned)p[3]);
-
- memset(&ts, 0, sizeof(ts));
- ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */
- ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */
- ts.tm_mday = msDate & 0x1f; /* Day of month. */
- ts.tm_hour = (msTime >> 11) & 0x1f;
- ts.tm_min = (msTime >> 5) & 0x3f;
- ts.tm_sec = (msTime << 1) & 0x3e;
- ts.tm_isdst = -1;
- return mktime(&ts);
-}
-
/*
* The extra data is stored as a list of
* id1+size1+data1 + id2+size2+data2 ...
@@ -978,7 +958,7 @@ zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry,
}
zip->init_decryption = (zip_entry->zip_flags & ZIP_ENCRYPTED);
zip_entry->compression = (char)archive_le16dec(p + 8);
- zip_entry->mtime = zip_time(p + 10);
+ zip_entry->mtime = dos_to_unix(archive_le32dec(p + 10));
zip_entry->crc32 = archive_le32dec(p + 14);
if (zip_entry->zip_flags & ZIP_LENGTH_AT_END)
zip_entry->decdat = p[11];
@@ -2134,15 +2114,15 @@ zipx_ppmd8_init(struct archive_read *a, struct zip *zip)
if(order < 2 || restore_method > 2) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
- "Invalid parameter set in PPMd8 stream (order=%" PRId32 ", "
- "restore=%" PRId32 ")", order, restore_method);
+ "Invalid parameter set in PPMd8 stream (order=%" PRIu32 ", "
+ "restore=%" PRIu32 ")", order, restore_method);
return (ARCHIVE_FAILED);
}
/* Allocate the memory needed to properly decompress the file. */
if(!__archive_ppmd8_functions.Ppmd8_Alloc(&zip->ppmd8, mem << 20)) {
archive_set_error(&a->archive, ENOMEM,
- "Unable to allocate memory for PPMd8 stream: %" PRId32 " bytes",
+ "Unable to allocate memory for PPMd8 stream: %" PRIu32 " bytes",
mem << 20);
return (ARCHIVE_FATAL);
}
@@ -3168,7 +3148,6 @@ archive_read_format_zip_read_data(struct archive_read *a,
/* We can't decompress this entry, but we will
* be able to skip() it and try the next entry. */
return (ARCHIVE_FAILED);
- break;
}
if (r != ARCHIVE_OK)
return (r);
@@ -3987,7 +3966,7 @@ slurp_central_directory(struct archive_read *a, struct archive_entry* entry,
zip->has_encrypted_entries = 1;
}
zip_entry->compression = (char)archive_le16dec(p + 10);
- zip_entry->mtime = zip_time(p + 12);
+ zip_entry->mtime = dos_to_unix(archive_le32dec(p + 12));
zip_entry->crc32 = archive_le32dec(p + 16);
if (zip_entry->zip_flags & ZIP_LENGTH_AT_END)
zip_entry->decdat = p[13];