mirror of
https://github.com/aaru-dps/Aaru.Compression.Native.git
synced 2025-12-16 19:24:31 +00:00
Fix possible partial decompression of LZIP.
This commit is contained in:
17
lzip.c
17
lzip.c
@@ -32,7 +32,7 @@ AARU_EXPORT int32_t AARU_CALL lzip_decode_buffer(uint8_t* dst_buffer,
|
|||||||
void* ctx;
|
void* ctx;
|
||||||
enum LZ_Errno lz_err;
|
enum LZ_Errno lz_err;
|
||||||
int32_t in_pos = 0, out_pos = 0, in_size;
|
int32_t in_pos = 0, out_pos = 0, in_size;
|
||||||
|
int rd;
|
||||||
// Initialize the decoder
|
// Initialize the decoder
|
||||||
ctx = LZ_decompress_open();
|
ctx = LZ_decompress_open();
|
||||||
lz_err = LZ_decompress_errno(ctx);
|
lz_err = LZ_decompress_errno(ctx);
|
||||||
@@ -57,13 +57,26 @@ AARU_EXPORT int32_t AARU_CALL lzip_decode_buffer(uint8_t* dst_buffer,
|
|||||||
|
|
||||||
in_pos += in_size;
|
in_pos += in_size;
|
||||||
|
|
||||||
int rd = LZ_decompress_read(ctx, dst_buffer + out_pos, dst_size);
|
rd = LZ_decompress_read(ctx, dst_buffer + out_pos, dst_size);
|
||||||
|
|
||||||
out_pos += rd;
|
out_pos += rd;
|
||||||
|
|
||||||
if(LZ_decompress_finished(ctx) == 1) break;
|
if(LZ_decompress_finished(ctx) == 1) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LZ_decompress_finish(ctx);
|
||||||
|
|
||||||
|
if(out_pos < dst_size)
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
rd = LZ_decompress_read(ctx, dst_buffer + out_pos, dst_size);
|
||||||
|
|
||||||
|
out_pos += rd;
|
||||||
|
|
||||||
|
if(LZ_compress_finished(ctx) == 1) break;
|
||||||
|
} while(rd > 0 && out_pos < dst_size);
|
||||||
|
}
|
||||||
|
|
||||||
// Free buffers
|
// Free buffers
|
||||||
LZ_decompress_close(ctx);
|
LZ_decompress_close(ctx);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user