mirror of
https://github.com/zlib-ng/minizip-ng
synced 2026-08-25 14:26:08 -04:00
Merge e5bae3ca49 into 7d2917b47f
This commit is contained in:
commit
95b2f50be2
8 changed files with 45 additions and 48 deletions
10
mz_strm.c
10
mz_strm.c
|
|
@ -153,7 +153,7 @@ 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_copy(void *target, void *source, int32_t len) {
|
||||
int32_t mz_stream_copy(void *target, void *source, int64_t len) {
|
||||
return mz_stream_copy_stream(target, NULL, source, NULL, len);
|
||||
}
|
||||
|
||||
|
|
@ -162,9 +162,9 @@ int32_t mz_stream_copy_to_end(void *target, void *source) {
|
|||
}
|
||||
|
||||
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 len) {
|
||||
uint8_t buf[16384];
|
||||
int32_t bytes_to_copy = 0;
|
||||
int64_t bytes_to_copy = 0;
|
||||
int32_t read = 0;
|
||||
int32_t written = 0;
|
||||
|
||||
|
|
@ -175,9 +175,9 @@ int32_t mz_stream_copy_stream(void *target, mz_stream_write_cb write_cb, void *s
|
|||
|
||||
while (len > 0) {
|
||||
bytes_to_copy = len;
|
||||
if (bytes_to_copy > (int32_t)sizeof(buf))
|
||||
if (bytes_to_copy > (int64_t)sizeof(buf))
|
||||
bytes_to_copy = sizeof(buf);
|
||||
read = read_cb(source, buf, bytes_to_copy);
|
||||
read = read_cb(source, buf, (int32_t)bytes_to_copy);
|
||||
if (read <= 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
written = write_cb(target, buf, read);
|
||||
|
|
|
|||
|
|
@ -88,10 +88,10 @@ 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_copy(void *target, void *source, int32_t len);
|
||||
int32_t mz_stream_copy(void *target, void *source, int64_t len);
|
||||
int32_t mz_stream_copy_to_end(void *target, void *source);
|
||||
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 len);
|
||||
int32_t mz_stream_copy_stream_to_end(void *target, mz_stream_write_cb write_cb, void *source,
|
||||
mz_stream_read_cb read_cb);
|
||||
int64_t mz_stream_tell(void *stream);
|
||||
|
|
|
|||
|
|
@ -41,25 +41,25 @@ typedef struct mz_stream_mem_s {
|
|||
mz_stream stream;
|
||||
int32_t mode;
|
||||
uint8_t *buffer; /* Memory buffer pointer */
|
||||
int32_t size; /* Size of the memory buffer */
|
||||
int32_t limit; /* Furthest we've written */
|
||||
int32_t position; /* Current position in the memory */
|
||||
int32_t grow_size; /* Size to grow when full */
|
||||
int64_t size; /* Size of the memory buffer */
|
||||
int64_t limit; /* Furthest we've written */
|
||||
int64_t position; /* Current position in the memory */
|
||||
int64_t grow_size; /* Size to grow when full */
|
||||
} mz_stream_mem;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static int32_t mz_stream_mem_set_size(void *stream, int32_t size) {
|
||||
static int32_t mz_stream_mem_set_size(void *stream, int64_t size) {
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
int32_t new_size = size;
|
||||
int64_t new_size = size;
|
||||
uint8_t *new_buf = NULL;
|
||||
|
||||
new_buf = (uint8_t *)malloc((uint32_t)new_size);
|
||||
new_buf = (uint8_t *)malloc((size_t)new_size);
|
||||
if (!new_buf)
|
||||
return MZ_BUF_ERROR;
|
||||
|
||||
if (mem->buffer) {
|
||||
memcpy(new_buf, mem->buffer, mem->size);
|
||||
memcpy(new_buf, mem->buffer, (size_t)mem->size);
|
||||
free(mem->buffer);
|
||||
}
|
||||
|
||||
|
|
@ -97,14 +97,14 @@ int32_t mz_stream_mem_read(void *stream, void *buf, int32_t size) {
|
|||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
|
||||
if (size > mem->size - mem->position)
|
||||
size = mem->size - mem->position;
|
||||
size = (int32_t)(mem->size - mem->position);
|
||||
if (mem->position + size > mem->limit)
|
||||
size = mem->limit - mem->position;
|
||||
size = (int32_t)(mem->limit - mem->position);
|
||||
|
||||
if (size <= 0)
|
||||
return 0;
|
||||
|
||||
memcpy(buf, mem->buffer + mem->position, size);
|
||||
memcpy(buf, mem->buffer + mem->position, (size_t)size);
|
||||
mem->position += size;
|
||||
|
||||
return size;
|
||||
|
|
@ -112,7 +112,7 @@ int32_t mz_stream_mem_read(void *stream, void *buf, int32_t size) {
|
|||
|
||||
int32_t mz_stream_mem_write(void *stream, const void *buf, int32_t size) {
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
int32_t new_size = 0;
|
||||
int64_t new_size = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (!size)
|
||||
|
|
@ -130,11 +130,11 @@ int32_t mz_stream_mem_write(void *stream, const void *buf, int32_t size) {
|
|||
if (err != MZ_OK)
|
||||
return err;
|
||||
} else {
|
||||
size = mem->size - mem->position;
|
||||
size = (int32_t)(mem->size - mem->position);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(mem->buffer + mem->position, buf, size);
|
||||
memcpy(mem->buffer + mem->position, buf, (size_t)size);
|
||||
|
||||
mem->position += size;
|
||||
if (mem->position > mem->limit)
|
||||
|
|
@ -167,21 +167,19 @@ int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin) {
|
|||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
// While `malloc` accepts a size_t, mz_stream_mem_s.size only supports an int32_t
|
||||
if (new_pos < 0 || new_pos > INT32_MAX) {
|
||||
if (new_pos < 0)
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
if (new_pos > mem->size) {
|
||||
if ((mem->mode & MZ_OPEN_MODE_CREATE) == 0)
|
||||
return MZ_SEEK_ERROR;
|
||||
|
||||
err = mz_stream_mem_set_size(stream, (int32_t)new_pos);
|
||||
err = mz_stream_mem_set_size(stream, new_pos);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
}
|
||||
|
||||
mem->position = (int32_t)new_pos;
|
||||
mem->position = new_pos;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +197,7 @@ int32_t mz_stream_mem_error(void *stream) {
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
void mz_stream_mem_set_buffer(void *stream, void *buf, int32_t size) {
|
||||
void mz_stream_mem_set_buffer(void *stream, void *buf, int64_t size) {
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
mem->buffer = (uint8_t *)buf;
|
||||
mem->size = size;
|
||||
|
|
@ -223,17 +221,17 @@ int32_t mz_stream_mem_get_buffer_at_current(void *stream, const void **buf) {
|
|||
return mz_stream_mem_get_buffer_at(stream, mem->position, buf);
|
||||
}
|
||||
|
||||
void mz_stream_mem_get_buffer_length(void *stream, int32_t *length) {
|
||||
void mz_stream_mem_get_buffer_length(void *stream, int64_t *length) {
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
*length = mem->limit;
|
||||
}
|
||||
|
||||
void mz_stream_mem_set_buffer_limit(void *stream, int32_t limit) {
|
||||
void mz_stream_mem_set_buffer_limit(void *stream, int64_t limit) {
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
mem->limit = limit;
|
||||
}
|
||||
|
||||
void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size) {
|
||||
void mz_stream_mem_set_grow_size(void *stream, int64_t grow_size) {
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
mem->grow_size = grow_size;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin);
|
|||
int32_t mz_stream_mem_close(void *stream);
|
||||
int32_t mz_stream_mem_error(void *stream);
|
||||
|
||||
void mz_stream_mem_set_buffer(void *stream, void *buf, int32_t size);
|
||||
void mz_stream_mem_set_buffer(void *stream, void *buf, int64_t size);
|
||||
int32_t mz_stream_mem_get_buffer(void *stream, const void **buf);
|
||||
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, const void **buf);
|
||||
int32_t mz_stream_mem_get_buffer_at_current(void *stream, const void **buf);
|
||||
void mz_stream_mem_get_buffer_length(void *stream, int32_t *length);
|
||||
void mz_stream_mem_set_buffer_limit(void *stream, int32_t limit);
|
||||
void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size);
|
||||
void mz_stream_mem_get_buffer_length(void *stream, int64_t *length);
|
||||
void mz_stream_mem_set_buffer_limit(void *stream, int64_t limit);
|
||||
void mz_stream_mem_set_grow_size(void *stream, int64_t grow_size);
|
||||
|
||||
void *mz_stream_mem_create(void);
|
||||
void mz_stream_mem_delete(void **stream);
|
||||
|
|
|
|||
2
mz_zip.c
2
mz_zip.c
|
|
@ -1408,7 +1408,7 @@ static int32_t mz_zip_recover_cd(void *handle) {
|
|||
|
||||
/* Set new upper seek boundary for central dir mem stream */
|
||||
disk_offset = mz_stream_tell(cd_mem_stream);
|
||||
mz_stream_mem_set_buffer_limit(cd_mem_stream, (int32_t)disk_offset);
|
||||
mz_stream_mem_set_buffer_limit(cd_mem_stream, disk_offset);
|
||||
|
||||
/* Set new central directory info */
|
||||
mz_zip_set_cd_stream(zip, 0, cd_mem_stream);
|
||||
|
|
|
|||
17
mz_zip_rw.c
17
mz_zip_rw.c
|
|
@ -170,10 +170,10 @@ int32_t mz_zip_reader_open_file_in_memory(void *handle, const char *path) {
|
|||
return MZ_MEM_ERROR;
|
||||
}
|
||||
|
||||
mz_stream_mem_set_grow_size(reader->mem_stream, (int32_t)file_size);
|
||||
mz_stream_mem_set_grow_size(reader->mem_stream, file_size);
|
||||
mz_stream_mem_open(reader->mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
|
||||
err = mz_stream_copy(reader->mem_stream, file_stream, (int32_t)file_size);
|
||||
err = mz_stream_copy(reader->mem_stream, file_stream, file_size);
|
||||
|
||||
mz_stream_os_close(file_stream);
|
||||
mz_stream_os_delete(&file_stream);
|
||||
|
|
@ -290,8 +290,7 @@ int32_t mz_zip_reader_unzip_cd(void *handle) {
|
|||
|
||||
err = mz_stream_seek(cd_mem_stream, 0, MZ_SEEK_SET);
|
||||
if (err == MZ_OK) {
|
||||
err = mz_stream_copy_stream(cd_mem_stream, NULL, handle, mz_zip_reader_entry_read,
|
||||
(int32_t)cd_info->uncompressed_size);
|
||||
err = mz_stream_copy_stream(cd_mem_stream, NULL, handle, mz_zip_reader_entry_read, cd_info->uncompressed_size);
|
||||
}
|
||||
|
||||
if (err == MZ_OK) {
|
||||
|
|
@ -1117,7 +1116,7 @@ int32_t mz_zip_writer_zip_cd(void *handle) {
|
|||
uint64_t number_entry = 0;
|
||||
int64_t cd_mem_length = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t extrafield_size = 0;
|
||||
int64_t extrafield_size = 0;
|
||||
void *file_extra_stream = NULL;
|
||||
void *cd_mem_stream = NULL;
|
||||
|
||||
|
|
@ -1155,7 +1154,7 @@ int32_t mz_zip_writer_zip_cd(void *handle) {
|
|||
|
||||
err = mz_zip_writer_entry_open(writer, &cd_file);
|
||||
if (err == MZ_OK) {
|
||||
mz_stream_copy_stream(writer, mz_zip_writer_entry_write, cd_mem_stream, NULL, (int32_t)cd_mem_length);
|
||||
mz_stream_copy_stream(writer, mz_zip_writer_entry_write, cd_mem_stream, NULL, cd_mem_length);
|
||||
|
||||
mz_stream_seek(cd_mem_stream, 0, MZ_SEEK_SET);
|
||||
mz_stream_mem_set_buffer_limit(cd_mem_stream, 0);
|
||||
|
|
@ -1311,10 +1310,10 @@ int32_t mz_zip_writer_open_file_in_memory(void *handle, const char *path) {
|
|||
return MZ_MEM_ERROR;
|
||||
}
|
||||
|
||||
mz_stream_mem_set_grow_size(writer->mem_stream, (int32_t)file_size);
|
||||
mz_stream_mem_set_grow_size(writer->mem_stream, file_size);
|
||||
mz_stream_mem_open(writer->mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
|
||||
err = mz_stream_copy(writer->mem_stream, file_stream, (int32_t)file_size);
|
||||
err = mz_stream_copy(writer->mem_stream, file_stream, file_size);
|
||||
|
||||
mz_stream_os_close(file_stream);
|
||||
mz_stream_os_delete(&file_stream);
|
||||
|
|
@ -1418,7 +1417,7 @@ int32_t mz_zip_writer_entry_close(void *handle) {
|
|||
int32_t err = MZ_OK;
|
||||
#ifndef MZ_ZIP_NO_CRYPTO
|
||||
const uint8_t *extrafield = NULL;
|
||||
int32_t extrafield_size = 0;
|
||||
int64_t extrafield_size = 0;
|
||||
int16_t field_length_hash = 0;
|
||||
uint8_t hash_digest[MZ_HASH_MAX_SIZE];
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|||
if (!stream)
|
||||
return 1;
|
||||
|
||||
mz_stream_mem_set_buffer(stream, (void *)data, (int32_t)size);
|
||||
mz_stream_mem_set_buffer(stream, (void *)data, (int64_t)size);
|
||||
|
||||
handle = mz_zip_create();
|
||||
if (!handle)
|
||||
|
|
|
|||
|
|
@ -36,14 +36,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|||
uint8_t value8 = 0;
|
||||
int16_t compress_level = 0;
|
||||
int64_t fuzz_pos = 0;
|
||||
int32_t fuzz_length = 0;
|
||||
int64_t fuzz_length = 0;
|
||||
uint8_t *fuzz_buf = NULL;
|
||||
const char *password = NULL;
|
||||
|
||||
fuzz_stream = mz_stream_mem_create();
|
||||
if (!fuzz_stream)
|
||||
return 1;
|
||||
mz_stream_mem_set_buffer(fuzz_stream, (void *)data, (int32_t)size);
|
||||
mz_stream_mem_set_buffer(fuzz_stream, (void *)data, (int64_t)size);
|
||||
|
||||
memset(&file_info, 0, sizeof(file_info));
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|||
fuzz_pos = mz_stream_tell(fuzz_stream);
|
||||
mz_stream_mem_get_buffer_length(fuzz_stream, &fuzz_length);
|
||||
|
||||
err = mz_zip_entry_write(handle, fuzz_buf, (fuzz_length - (int32_t)fuzz_pos));
|
||||
err = mz_zip_entry_write(handle, fuzz_buf, (int32_t)(fuzz_length - fuzz_pos));
|
||||
|
||||
mz_zip_entry_close(handle);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue