1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

szip: update to 0.2.4 (#15296)

This commit is contained in:
Dialga 2022-08-01 09:47:45 +12:00 committed by GitHub
parent fa75713bc3
commit dc78f1ba17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 34 deletions

View File

@ -6457,11 +6457,10 @@ mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName,
return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND);
}
mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip,
mz_uint file_index, void *pBuf,
size_t buf_size, mz_uint flags,
void *pUser_read_buf,
size_t user_read_buf_size) {
static mz_bool mz_zip_reader_extract_to_mem_no_alloc1(
mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size,
mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size,
const mz_zip_archive_file_stat *st) {
int status = TINFL_STATUS_DONE;
mz_uint64 needed_size, cur_file_ofs, comp_remaining,
out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail;
@ -6477,11 +6476,13 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip,
((user_read_buf_size) && (!pUser_read_buf)) || (!pZip->m_pRead))
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
if (st) {
file_stat = *st;
} else if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
return MZ_FALSE;
/* A directory or zero length file */
if (file_stat.m_is_directory || (!file_stat.m_comp_size))
if ((file_stat.m_is_directory) || (!file_stat.m_comp_size))
return MZ_TRUE;
/* Encryption and patch files are not supported. */
@ -6616,6 +6617,16 @@ mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip,
return status == TINFL_STATUS_DONE;
}
mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip,
mz_uint file_index, void *pBuf,
size_t buf_size, mz_uint flags,
void *pUser_read_buf,
size_t user_read_buf_size) {
return mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf,
buf_size, flags, pUser_read_buf,
user_read_buf_size, NULL);
}
mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(
mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size,
mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size) {
@ -6643,22 +6654,18 @@ mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip,
void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index,
size_t *pSize, mz_uint flags) {
mz_uint64 comp_size, uncomp_size, alloc_size;
const mz_uint8 *p = mz_zip_get_cdh(pZip, file_index);
mz_zip_archive_file_stat file_stat;
mz_uint64 alloc_size;
void *pBuf;
if (pSize)
*pSize = 0;
if (!p) {
mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat))
return NULL;
}
comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS);
uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS);
alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size;
alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size
: file_stat.m_uncomp_size;
if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) {
mz_zip_set_error(pZip, MZ_ZIP_INTERNAL_ERROR);
return NULL;
@ -6670,8 +6677,9 @@ void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index,
return NULL;
}
if (!mz_zip_reader_extract_to_mem(pZip, file_index, pBuf, (size_t)alloc_size,
flags)) {
if (!mz_zip_reader_extract_to_mem_no_alloc1(pZip, file_index, pBuf,
(size_t)alloc_size, flags, NULL,
0, &file_stat)) {
pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf);
return NULL;
}

26
thirdparty/zip/zip.c vendored
View File

@ -583,20 +583,15 @@ static ssize_t zip_file_move(MZ_FILE *m_pFile, const mz_uint64 to,
return ZIP_ECAPSIZE;
}
if (MZ_FSEEK64(m_pFile, from, SEEK_SET)) {
MZ_FCLOSE(m_pFile);
return ZIP_EFSEEK;
}
if (fread(move_buf, 1, length, m_pFile) != length) {
MZ_FCLOSE(m_pFile);
return ZIP_EFREAD;
}
if (MZ_FSEEK64(m_pFile, to, SEEK_SET)) {
MZ_FCLOSE(m_pFile);
return ZIP_EFSEEK;
}
if (fwrite(move_buf, 1, length, m_pFile) != length) {
MZ_FCLOSE(m_pFile);
return ZIP_EFWRITE;
}
return (ssize_t)length;
@ -662,7 +657,7 @@ static int zip_central_dir_move(mz_zip_internal_state *pState, int begin,
d_size = (mz_uint32)(next - deleted);
}
if (l_size == 0) {
if (next && l_size == 0) {
memmove(pState->m_central_dir.m_p, next, r_size);
pState->m_central_dir.m_p = MZ_REALLOC(pState->m_central_dir.m_p, r_size);
{
@ -674,7 +669,7 @@ static int zip_central_dir_move(mz_zip_internal_state *pState, int begin,
}
}
if (l_size * r_size != 0) {
if (next && l_size * r_size != 0) {
memmove(deleted, next, r_size);
{
int i;
@ -697,12 +692,12 @@ static int zip_central_dir_delete(mz_zip_internal_state *pState,
int end = 0;
int d_num = 0;
while (i < entry_num) {
while ((!deleted_entry_index_array[i]) && (i < entry_num)) {
while ((i < entry_num) && (!deleted_entry_index_array[i])) {
i++;
}
begin = i;
while ((deleted_entry_index_array[i]) && (i < entry_num)) {
while ((i < entry_num) && (deleted_entry_index_array[i])) {
i++;
}
end = i;
@ -711,14 +706,14 @@ static int zip_central_dir_delete(mz_zip_internal_state *pState,
i = 0;
while (i < entry_num) {
while ((!deleted_entry_index_array[i]) && (i < entry_num)) {
while ((i < entry_num) && (!deleted_entry_index_array[i])) {
i++;
}
begin = i;
if (begin == entry_num) {
break;
}
while ((deleted_entry_index_array[i]) && (i < entry_num)) {
while ((i < entry_num) && (deleted_entry_index_array[i])) {
i++;
}
end = i;
@ -764,13 +759,13 @@ static ssize_t zip_entries_delete_mark(struct zip_t *zip,
}
while (i < entry_num) {
while ((entry_mark[i].type == MZ_KEEP) && (i < entry_num)) {
while ((i < entry_num) && (entry_mark[i].type == MZ_KEEP)) {
writen_num += entry_mark[i].lf_length;
read_num = writen_num;
i++;
}
while ((entry_mark[i].type == MZ_DELETE) && (i < entry_num)) {
while ((i < entry_num) && (entry_mark[i].type == MZ_DELETE)) {
deleted_entry_flag_array[i] = MZ_TRUE;
read_num += entry_mark[i].lf_length;
deleted_length += entry_mark[i].lf_length;
@ -778,7 +773,7 @@ static ssize_t zip_entries_delete_mark(struct zip_t *zip,
deleted_entry_num++;
}
while ((entry_mark[i].type == MZ_MOVE) && (i < entry_num)) {
while ((i < entry_num) && (entry_mark[i].type == MZ_MOVE)) {
move_length += entry_mark[i].lf_length;
mz_uint8 *p = &MZ_ZIP_ARRAY_ELEMENT(
&pState->m_central_dir, mz_uint8,
@ -1191,7 +1186,7 @@ int zip_entry_close(struct zip_t *zip) {
mz_uint32 extra_size = 0;
mz_uint8 extra_data[MZ_ZIP64_MAX_CENTRAL_EXTRA_FIELD_SIZE];
mz_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64];
mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32;
mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE64;
if (!zip) {
// zip_t handler is not initialized
@ -1226,7 +1221,6 @@ int zip_entry_close(struct zip_t *zip) {
MZ_WRITE_LE32(local_dir_footer + 4, zip->entry.uncomp_crc32);
MZ_WRITE_LE64(local_dir_footer + 8, zip->entry.comp_size);
MZ_WRITE_LE64(local_dir_footer + 16, zip->entry.uncomp_size);
local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE64;
if (pzip->m_pWrite(pzip->m_pIO_opaque, zip->entry.offset, local_dir_footer,
local_dir_footer_size) != local_dir_footer_size) {