mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-09 02:07:06 -06:00
Update lz4, lz5 and zstd to latest stable series
- added some more error checking in zstdmt also
This commit is contained in:
@@ -158,6 +158,24 @@ static int IsZstd_Skippable(unsigned char *buf)
|
||||
return (MEM_readLE32(buf) == ZSTDMT_MAGIC_SKIPPABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* mt_error - return mt lib specific error code
|
||||
*/
|
||||
static size_t mt_error(int rv)
|
||||
{
|
||||
switch (rv) {
|
||||
case -1:
|
||||
return ZSTDMT_ERROR(read_fail);
|
||||
case -2:
|
||||
return ZSTDMT_ERROR(canceled);
|
||||
case -3:
|
||||
return ZSTDMT_ERROR(memory_allocation);
|
||||
}
|
||||
|
||||
/* XXX, some catch all other errors */
|
||||
return ZSTDMT_ERROR(read_fail);
|
||||
}
|
||||
|
||||
/**
|
||||
* pt_write - queue for decompressed output
|
||||
*/
|
||||
@@ -173,10 +191,8 @@ static size_t pt_write(ZSTDMT_DCtx * ctx, struct writelist *wl)
|
||||
wl = list_entry(entry, struct writelist, node);
|
||||
if (wl->frame == ctx->curframe) {
|
||||
int rv = ctx->fn_write(ctx->arg_write, &wl->out);
|
||||
if (rv == -1)
|
||||
return ZSTDMT_ERROR(write_fail);
|
||||
if (rv == -2)
|
||||
return ZSTDMT_ERROR(canceled);
|
||||
if (rv < 0)
|
||||
return mt_error(rv);
|
||||
ctx->outsize += wl->out.size;
|
||||
ctx->curframe++;
|
||||
list_move(entry, &ctx->writelist_free);
|
||||
@@ -217,10 +233,10 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame)
|
||||
hdr.buf = hdrbuf + 7;
|
||||
hdr.size = 5;
|
||||
rv = ctx->fn_read(ctx->arg_read, &hdr);
|
||||
if (rv == -1)
|
||||
goto error_read;
|
||||
if (rv == -2)
|
||||
goto error_read;
|
||||
if (rv < 0) {
|
||||
pthread_mutex_unlock(&ctx->read_mutex);
|
||||
return mt_error(rv);
|
||||
}
|
||||
if (hdr.size != 5)
|
||||
goto error_data;
|
||||
hdr.buf = hdrbuf;
|
||||
@@ -234,8 +250,10 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame)
|
||||
goto error_nomem;
|
||||
in->allocated = in->size;
|
||||
rv = ctx->fn_read(ctx->arg_read, in);
|
||||
if (rv == -1)
|
||||
goto error_read;
|
||||
if (rv < 0) {
|
||||
pthread_mutex_unlock(&ctx->read_mutex);
|
||||
return mt_error(rv);
|
||||
}
|
||||
if (in->size != toRead)
|
||||
goto error_data;
|
||||
ctx->insize += in->size;
|
||||
@@ -264,8 +282,10 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame)
|
||||
in->buf = start + 4;
|
||||
in->size = toRead - 4;
|
||||
rv = ctx->fn_read(ctx->arg_read, in);
|
||||
if (rv == -1)
|
||||
goto error_read;
|
||||
if (rv < 0) {
|
||||
pthread_mutex_unlock(&ctx->read_mutex);
|
||||
return mt_error(rv);
|
||||
}
|
||||
if (in->size != toRead - 4)
|
||||
goto error_data;
|
||||
ctx->insize += in->size;
|
||||
@@ -286,10 +306,10 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame)
|
||||
hdr.buf = hdrbuf;
|
||||
hdr.size = 12;
|
||||
rv = ctx->fn_read(ctx->arg_read, &hdr);
|
||||
if (rv == -1)
|
||||
goto error_read;
|
||||
if (rv == -2)
|
||||
goto error_canceled;
|
||||
if (rv < 0) {
|
||||
pthread_mutex_unlock(&ctx->read_mutex);
|
||||
return mt_error(rv);
|
||||
}
|
||||
|
||||
/* eof reached ? */
|
||||
if (unlikely(hdr.size == 0)) {
|
||||
@@ -325,7 +345,7 @@ static size_t pt_read(ZSTDMT_DCtx * ctx, ZSTDMT_Buffer * in, size_t * frame)
|
||||
if (rv == -1)
|
||||
goto error_read;
|
||||
if (rv == -2)
|
||||
goto error_canceled;
|
||||
goto error_canceled;
|
||||
/* needed more bytes! */
|
||||
if (in->size != toRead)
|
||||
goto error_data;
|
||||
@@ -361,12 +381,12 @@ static void *pt_decompress(void *arg)
|
||||
size_t result = 0;
|
||||
ZSTDMT_Buffer collect;
|
||||
|
||||
/* init dstream stream */
|
||||
result = ZSTD_initDStream(w->dctx);
|
||||
if (ZSTD_isError(result)) {
|
||||
zstdmt_errcode = result;
|
||||
return (void *)ZSTDMT_ERROR(compression_library);
|
||||
}
|
||||
/* init dstream stream */
|
||||
result = ZSTD_initDStream(w->dctx);
|
||||
if (ZSTD_isError(result)) {
|
||||
zstdmt_errcode = result;
|
||||
return (void *)ZSTDMT_ERROR(compression_library);
|
||||
}
|
||||
|
||||
collect.buf = 0;
|
||||
collect.size = 0;
|
||||
@@ -452,7 +472,8 @@ static void *pt_decompress(void *arg)
|
||||
bnew = malloc(collect.size + zOut.pos);
|
||||
if (!bnew) {
|
||||
result =
|
||||
ZSTDMT_ERROR(memory_allocation);
|
||||
ZSTDMT_ERROR
|
||||
(memory_allocation);
|
||||
goto error_lock;
|
||||
}
|
||||
memcpy((char *)bnew, collect.buf,
|
||||
@@ -496,7 +517,8 @@ static void *pt_decompress(void *arg)
|
||||
pthread_mutex_unlock(&ctx->write_mutex);
|
||||
out->buf = realloc(out->buf, out->size);
|
||||
if (!out->buf) {
|
||||
result = ZSTDMT_ERROR(memory_allocation);
|
||||
result =
|
||||
ZSTDMT_ERROR(memory_allocation);
|
||||
goto error_lock;
|
||||
}
|
||||
out->allocated = out->size;
|
||||
@@ -581,8 +603,8 @@ static size_t st_decompress(void *arg)
|
||||
|
||||
/* read more bytes, to fill buffer */
|
||||
rv = ctx->fn_read(ctx->arg_read, in);
|
||||
if (rv == -1) {
|
||||
result = ZSTDMT_ERROR(read_fail);
|
||||
if (rv < 0) {
|
||||
result = mt_error(rv);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -621,6 +643,10 @@ static size_t st_decompress(void *arg)
|
||||
return ZSTDMT_ERROR(canceled);
|
||||
goto error_clib;
|
||||
}
|
||||
if (rv == -3) {
|
||||
return ZSTDMT_ERROR(memory_allocation);
|
||||
goto error_clib;
|
||||
}
|
||||
ctx->outsize += zOut.pos;
|
||||
}
|
||||
|
||||
@@ -643,8 +669,8 @@ static size_t st_decompress(void *arg)
|
||||
/* read next input */
|
||||
in->size = in->allocated;
|
||||
rv = ctx->fn_read(ctx->arg_read, in);
|
||||
if (rv == -1) {
|
||||
result = ZSTDMT_ERROR(read_fail);
|
||||
if (rv < 0) {
|
||||
result = mt_error(rv);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -706,8 +732,8 @@ size_t ZSTDMT_decompressDCtx(ZSTDMT_DCtx * ctx, ZSTDMT_RdWr_t * rdwr)
|
||||
in->buf = buf;
|
||||
in->size = 16;
|
||||
rv = ctx->fn_read(ctx->arg_read, in);
|
||||
if (rv == -1)
|
||||
return ZSTDMT_ERROR(read_fail);
|
||||
if (rv < 0)
|
||||
return mt_error(rv);
|
||||
|
||||
/* must be single threaded standard zstd, when smaller 16 bytes */
|
||||
if (in->size < 16) {
|
||||
|
||||
Reference in New Issue
Block a user