mirror of
https://github.com/zlib-ng/minizip-ng
synced 2025-03-28 21:13:18 +00:00
fix decompress zstd error
This commit is contained in:
parent
432fcc712b
commit
7cecfa6472
@ -107,48 +107,51 @@ int32_t mz_stream_zstd_read(void *stream, void *buf, int32_t size) {
|
||||
uint64_t total_in_after = 0;
|
||||
uint64_t total_out_before = 0;
|
||||
uint64_t total_out_after = 0;
|
||||
uint32_t total_in = 0;
|
||||
uint32_t total_out = 0;
|
||||
uint32_t in_bytes = 0;
|
||||
uint32_t out_bytes = 0;
|
||||
int32_t bytes_to_read = sizeof(zstd->buffer);
|
||||
int32_t total_in = 0;
|
||||
int32_t total_out = 0;
|
||||
int32_t in_bytes = 0;
|
||||
int32_t out_bytes = 0;
|
||||
int32_t bytes_to_read = 0;
|
||||
int32_t read = 0;
|
||||
size_t result = 0;
|
||||
size_t error_code = 0;
|
||||
|
||||
zstd->out.dst = (void*)buf;
|
||||
zstd->out.size = (size_t)size;
|
||||
zstd->out.pos = 0;
|
||||
zstd->out.dst = buf;
|
||||
zstd->out.size = size;
|
||||
|
||||
do {
|
||||
if (zstd->in.pos == zstd->in.size) {
|
||||
bytes_to_read = sizeof(zstd->buffer);
|
||||
if (zstd->max_total_in > 0) {
|
||||
if ((int64_t)bytes_to_read > (zstd->max_total_in - zstd->total_in))
|
||||
bytes_to_read = (int32_t)(zstd->max_total_in - zstd->total_in);
|
||||
}
|
||||
|
||||
read = mz_stream_read(zstd->stream.base, zstd->buffer, bytes_to_read);
|
||||
|
||||
if (read < 0)
|
||||
return read;
|
||||
|
||||
zstd->in.src = zstd->buffer;
|
||||
zstd->in.size = read;
|
||||
zstd->in.src = (const void*)zstd->buffer;
|
||||
zstd->in.pos = 0;
|
||||
zstd->in.size = (size_t)read;
|
||||
}
|
||||
|
||||
total_out_before = zstd->out.pos;
|
||||
total_in_before = zstd->in.pos;
|
||||
total_out_before = zstd->out.pos;
|
||||
|
||||
result = ZSTD_decompressStream(zstd->zdstream, &zstd->out, &zstd->in);
|
||||
error_code = ZSTD_decompressStream(zstd->zdstream, &zstd->out, &zstd->in);
|
||||
|
||||
if (ZSTD_isError(result)) {
|
||||
zstd->error = (int32_t)result;
|
||||
if (ZSTD_isError(error_code)) {
|
||||
zstd->error = error_code;
|
||||
return MZ_DATA_ERROR;
|
||||
}
|
||||
|
||||
total_in_after = zstd->in.pos;
|
||||
total_out_after = zstd->out.pos;
|
||||
|
||||
in_bytes += (uint32_t)(total_in_after - total_in_before);
|
||||
out_bytes += (uint32_t)(total_out_after - total_out_before);
|
||||
in_bytes = (int32_t)(total_in_after - total_in_before);
|
||||
out_bytes = (int32_t)(total_out_after - total_out_before);
|
||||
|
||||
total_in += in_bytes;
|
||||
total_out += out_bytes;
|
||||
@ -156,7 +159,8 @@ int32_t mz_stream_zstd_read(void *stream, void *buf, int32_t size) {
|
||||
zstd->total_in += in_bytes;
|
||||
zstd->total_out += out_bytes;
|
||||
|
||||
} while (zstd->out.pos < zstd->out.size && result > 0);
|
||||
|
||||
} while (zstd->total_in != zstd->max_total_in && zstd->out.pos != zstd->out.size);
|
||||
|
||||
return total_out;
|
||||
#endif
|
||||
|
4
mz_zip.c
4
mz_zip.c
@ -1739,6 +1739,10 @@ static int32_t mz_zip_entry_open_int(void *handle, uint8_t raw, int16_t compress
|
||||
mz_stream_set_prop_int64(zip->compress_stream, MZ_STREAM_PROP_TOTAL_IN_MAX, zip->file_info.compressed_size);
|
||||
mz_stream_set_prop_int64(zip->compress_stream, MZ_STREAM_PROP_TOTAL_OUT_MAX, zip->file_info.uncompressed_size);
|
||||
}
|
||||
if ((zip->file_info.compression_method == MZ_COMPRESS_METHOD_ZSTD || zip->file_info.compression_method == MZ_COMPRESS_METHOD_WZZSTD)) {
|
||||
mz_stream_set_prop_int64(zip->compress_stream, MZ_STREAM_PROP_TOTAL_IN_MAX, zip->file_info.compressed_size);
|
||||
mz_stream_set_prop_int64(zip->compress_stream, MZ_STREAM_PROP_TOTAL_OUT_MAX, zip->file_info.uncompressed_size);
|
||||
}
|
||||
}
|
||||
|
||||
mz_stream_set_base(zip->compress_stream, zip->crypt_stream);
|
||||
|
Loading…
x
Reference in New Issue
Block a user