mirror of
https://github.com/zlib-ng/minizip-ng
synced 2026-08-25 14:26:08 -04:00
Fix allocating negative size
This commit is contained in:
parent
9a2a6be955
commit
f890d80348
1 changed files with 5 additions and 2 deletions
|
|
@ -167,6 +167,11 @@ 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) {
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
if (new_pos > mem->size) {
|
||||
if ((mem->mode & MZ_OPEN_MODE_CREATE) == 0)
|
||||
return MZ_SEEK_ERROR;
|
||||
|
|
@ -174,8 +179,6 @@ int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin) {
|
|||
err = mz_stream_mem_set_size(stream, (int32_t)new_pos);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
} else if (new_pos < 0) {
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
mem->position = (int32_t)new_pos;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue