Fixed mismatching NTFS date/time causing decryption failure. #527

This commit is contained in:
Nathan Moinvaziri 2020-11-30 21:30:10 -08:00
parent af49f4652b
commit 9ffb08e41b
2 changed files with 16 additions and 17 deletions

View File

@ -239,6 +239,19 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
}
if (err == MZ_OK)
err = mz_stream_read_uint32(stream, &file_info->crc);
if (err == MZ_OK && file_info->flag & MZ_ZIP_FLAG_ENCRYPTED) {
/* Info-ZIP modification to ZipCrypto format: if bit 3 of the general
* purpose bit flag is set, it uses high byte of 16-bit File Time. */
if (file_info->flag & MZ_ZIP_FLAG_DATA_DESCRIPTOR)
file_info->pk_verify = ((dos_date >> 16) & 0xff) << 8 |
((dos_date >> 8) & 0xff);
else
file_info->pk_verify = ((file_info->crc >> 16) & 0xff) << 8 |
((file_info->crc >> 24) & 0xff);
}
if (err == MZ_OK) {
err = mz_stream_read_uint32(stream, &value32);
file_info->compressed_size = value32;
@ -1663,23 +1676,8 @@ static int32_t mz_zip_entry_open_int(void *handle, uint8_t raw, int16_t compress
#endif
{
#ifdef HAVE_PKCRYPT
uint8_t verify1 = 0;
uint8_t verify2 = 0;
/* Info-ZIP modification to ZipCrypto format: */
/* If bit 3 of the general purpose bit flag is set, it uses high byte of 16-bit File Time. */
if (zip->file_info.flag & MZ_ZIP_FLAG_DATA_DESCRIPTOR) {
uint32_t dos_date = 0;
dos_date = mz_zip_time_t_to_dos_date(zip->file_info.modified_date);
verify1 = (uint8_t)((dos_date >> 16) & 0xff);
verify2 = (uint8_t)((dos_date >> 8) & 0xff);
} else {
verify1 = (uint8_t)((zip->file_info.crc >> 16) & 0xff);
verify2 = (uint8_t)((zip->file_info.crc >> 24) & 0xff);
}
uint8_t verify1 = (uint8_t)((zip->file_info.pk_verify >> 8) & 0xff);
uint8_t verify2 = (uint8_t)((zip->file_info.pk_verify) & 0xff);
mz_stream_pkcrypt_create(&zip->crypt_stream);
mz_stream_pkcrypt_set_password(zip->crypt_stream, password);

View File

@ -49,6 +49,7 @@ typedef struct mz_zip_file_s {
uint16_t zip64; /* zip64 extension mode */
uint16_t aes_version; /* winzip aes extension if not 0 */
uint8_t aes_encryption_mode; /* winzip aes encryption mode */
uint16_t pk_verify; /* pkware encryption verifier */
} mz_zip_file, mz_zip_entry;