Fixed disk offset not being read correctly with zip64. #279

Fixed zipOpen2_64 not working correctly with APPEND_STATUS_CREATE.
This commit is contained in:
Nathan Moinvaziri 2018-07-13 12:31:39 -07:00
parent f873eccdd2
commit 2ecd8a0b2a
2 changed files with 22 additions and 10 deletions

View File

@ -54,7 +54,7 @@ extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **gl
zlib_filefunc64_def *pzlib_filefunc_def)
{
mz_compat *compat = NULL;
int32_t mode = MZ_OPEN_MODE_READWRITE;
int32_t mode = MZ_OPEN_MODE_WRITE;
void *handle = NULL;
void *stream = NULL;
@ -75,9 +75,10 @@ extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **gl
mode |= MZ_OPEN_MODE_CREATE;
break;
case APPEND_STATUS_CREATEAFTER:
mode |= MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_APPEND;
mode |= MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_APPEND | MZ_OPEN_MODE_READ;
break;
case APPEND_STATUS_ADDINZIP:
mode |= MZ_OPEN_MODE_READ;
break;
}

View File

@ -684,11 +684,15 @@ 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)
{
err = mz_stream_read_uint32(stream, &value32);
file_info->compressed_size = value32;
file_info->compressed_size = value32;
}
if (err == MZ_OK)
{
err = mz_stream_read_uint32(stream, &value32);
file_info->uncompressed_size = value32;
file_info->uncompressed_size = value32;
}
if (err == MZ_OK)
err = mz_stream_read_uint16(stream, &file_info->filename_size);
if (err == MZ_OK)
@ -698,15 +702,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_uint16(stream, &file_info->comment_size);
if (err == MZ_OK)
{
err = mz_stream_read_uint16(stream, &value16);
file_info->disk_number = value16;
file_info->disk_number = value16;
}
if (err == MZ_OK)
err = mz_stream_read_uint16(stream, &file_info->internal_fa);
if (err == MZ_OK)
err = mz_stream_read_uint32(stream, &file_info->external_fa);
if (err == MZ_OK)
{
err = mz_stream_read_uint32(stream, &value32);
file_info->disk_offset = value32;
file_info->disk_offset = value32;
}
}
}
@ -755,8 +763,7 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
if ((err == MZ_OK) && (file_info->compressed_size == UINT32_MAX))
err = mz_stream_read_uint64(file_info_stream, &file_info->compressed_size);
if ((err == MZ_OK) && (file_info->disk_offset == UINT32_MAX))
err = mz_stream_read_uint64(file_info_stream, &value64);
file_info->disk_offset = value64;
err = mz_stream_read_uint64(file_info_stream, &file_info->disk_offset);
if ((err == MZ_OK) && (file_info->disk_number == UINT16_MAX))
err = mz_stream_read_uint32(file_info_stream, &file_info->disk_number);
}
@ -819,11 +826,15 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
err = MZ_FORMAT_ERROR;
// Get AES encryption strength and actual compression method
if (err == MZ_OK)
{
err = mz_stream_read_uint8(file_info_stream, &value8);
file_info->aes_encryption_mode = value8;
file_info->aes_encryption_mode = value8;
}
if (err == MZ_OK)
{
err = mz_stream_read_uint16(file_info_stream, &value16);
file_info->compression_method = value16;
file_info->compression_method = value16;
}
}
#endif
else