Fix corrupt archive if uncompressed file smaller than 4 byte and file is added by mz_zip_writer_add_mem*
This commit is contained in:
parent
3616bf804b
commit
46cdde2ac5
22
miniz_zip.c
22
miniz_zip.c
@ -3186,6 +3186,17 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
|||||||
}
|
}
|
||||||
#endif /* #ifndef MINIZ_NO_TIME */
|
#endif /* #ifndef MINIZ_NO_TIME */
|
||||||
|
|
||||||
|
if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
|
||||||
|
{
|
||||||
|
uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, buf_size);
|
||||||
|
uncomp_size = buf_size;
|
||||||
|
if (uncomp_size <= 3)
|
||||||
|
{
|
||||||
|
level = 0;
|
||||||
|
store_data_uncompressed = MZ_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
archive_name_size = strlen(pArchive_name);
|
archive_name_size = strlen(pArchive_name);
|
||||||
if (archive_name_size > MZ_UINT16_MAX)
|
if (archive_name_size > MZ_UINT16_MAX)
|
||||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME);
|
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_FILENAME);
|
||||||
@ -3309,17 +3320,6 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
|||||||
cur_archive_file_ofs += user_extra_data_len;
|
cur_archive_file_ofs += user_extra_data_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA))
|
|
||||||
{
|
|
||||||
uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, buf_size);
|
|
||||||
uncomp_size = buf_size;
|
|
||||||
if (uncomp_size <= 3)
|
|
||||||
{
|
|
||||||
level = 0;
|
|
||||||
store_data_uncompressed = MZ_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (store_data_uncompressed)
|
if (store_data_uncompressed)
|
||||||
{
|
{
|
||||||
if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size)
|
if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user