Fixed issues copying variable length data internally when large extrafield or comment.

This commit is contained in:
Nathan Moinvaziri 2018-11-23 11:41:35 -08:00
parent 2eb2907823
commit 6b64b924af
3 changed files with 20 additions and 20 deletions

View File

@ -171,14 +171,6 @@ int32_t mz_stream_write_uint64(void *stream, uint64_t value)
return mz_stream_write_value(stream, value, sizeof(uint64_t));
}
int32_t mz_stream_write_chars(void *stream, const char *value, uint8_t null_terminate)
{
int32_t len = (int32_t)strlen(value);
if (null_terminate)
len += 1;
return mz_stream_write(stream, value, len);
}
int32_t mz_stream_copy(void *target, void *source, int32_t len)
{
return mz_stream_copy_stream(target, NULL, source, NULL, len);

View File

@ -88,7 +88,6 @@ int32_t mz_stream_write_uint16(void *stream, uint16_t value);
int32_t mz_stream_write_uint32(void *stream, uint32_t value);
int32_t mz_stream_write_int64(void *stream, int64_t value);
int32_t mz_stream_write_uint64(void *stream, uint64_t value);
int32_t mz_stream_write_chars(void *stream, const char *value, uint8_t null_terminate);
int32_t mz_stream_copy(void *target, void *source, int32_t len);
int32_t mz_stream_copy_stream(void *target, mz_stream_write_cb write_cb, void *source, mz_stream_read_cb read_cb, int32_t len);
int64_t mz_stream_tell(void *stream);

View File

@ -1786,6 +1786,9 @@ int32_t mz_zip_entry_read_open(void *handle, uint8_t raw, const char *password)
int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info, int16_t compress_level, uint8_t raw, const char *password)
{
mz_zip *zip = (mz_zip *)handle;
int64_t filename_pos = -1;
int64_t extrafield_pos = -1;
int64_t comment_pos = -1;
int64_t disk_number = 0;
uint8_t is_dir = 0;
int32_t err = MZ_OK;
@ -1813,21 +1816,27 @@ int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info, int1
mz_stream_write(zip->file_info_stream, file_info, sizeof(mz_zip_file));
/* Copy filename, extrafield, and comment internally */
filename_pos = mz_stream_tell(zip->file_info_stream);
if (file_info->filename != NULL)
{
mz_stream_mem_get_buffer_at_current(zip->file_info_stream, (const void **)&zip->file_info.filename);
mz_stream_write_chars(zip->file_info_stream, file_info->filename, 1);
}
mz_stream_write(zip->file_info_stream, file_info->filename, (int32_t)strlen(file_info->filename));
mz_stream_write_uint8(zip->file_info_stream, 0);
extrafield_pos = mz_stream_tell(zip->file_info_stream);
if (file_info->extrafield != NULL)
{
mz_stream_mem_get_buffer_at_current(zip->file_info_stream, (const void **)&zip->file_info.extrafield);
mz_stream_write(zip->file_info_stream, file_info->extrafield, file_info->extrafield_size);
}
mz_stream_write_uint8(zip->file_info_stream, 0);
comment_pos = mz_stream_tell(zip->file_info_stream);
if (file_info->comment != NULL)
{
mz_stream_mem_get_buffer_at_current(zip->file_info_stream, (const void **)&zip->file_info.comment);
mz_stream_write_chars(zip->file_info_stream, file_info->comment, 1);
}
mz_stream_write(zip->file_info_stream, file_info->comment, file_info->comment_size);
mz_stream_write_uint8(zip->file_info_stream, 0);
if (filename_pos > 0)
mz_stream_mem_get_buffer_at(zip->file_info_stream, filename_pos, (const void **)&zip->file_info.filename);
if (extrafield_pos > 0)
mz_stream_mem_get_buffer_at(zip->file_info_stream, extrafield_pos, (const void **)&zip->file_info.extrafield);
if (comment_pos > 0)
mz_stream_mem_get_buffer_at(zip->file_info_stream, comment_pos, (const void **)&zip->file_info.comment);
if (zip->file_info.compression_method == MZ_COMPRESS_METHOD_DEFLATE)
{