summaryrefslogtreecommitdiff
path: root/src/common/compress_zstd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/compress_zstd.c')
-rw-r--r--src/common/compress_zstd.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c
index 99d05c37bd..a136db48bf 100644
--- a/src/common/compress_zstd.c
+++ b/src/common/compress_zstd.c
@@ -312,6 +312,8 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
return TOR_COMPRESS_ERROR;
}
+ // ZSTD_flushStream returns 0 if the frame is done, or >0 if it
+ // is incomplete.
if (retval > 0)
return TOR_COMPRESS_BUFFER_FULL;
}
@@ -319,7 +321,7 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
if (!finish) {
// We're not done with the input, so no need to flush.
return TOR_COMPRESS_OK;
- } else if (state->compress && finish) {
+ } else if (state->compress) {
retval = ZSTD_endStream(state->u.compress_stream, &output);
*out = (char *)output.dst + output.pos;
@@ -338,10 +340,20 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
return TOR_COMPRESS_BUFFER_FULL;
return TOR_COMPRESS_DONE;
- } else {
- // ZSTD_flushStream returns 0 if the frame is done, or >0 if it
+ } else /* if (!state->compress) */ {
+ // ZSTD_decompressStream returns 0 if the frame is done, or >0 if it
// is incomplete.
- return (retval == 0) ? TOR_COMPRESS_DONE : TOR_COMPRESS_OK;
+ // We check this above.
+ tor_assert_nonfatal(!ZSTD_isError(retval));
+ // Start a new frame if this frame is done
+ if (retval == 0)
+ return TOR_COMPRESS_DONE;
+ // Don't check out_len, it might have some space left if the next output
+ // chunk is larger than the remaining space
+ else if (*in_len > 0)
+ return TOR_COMPRESS_BUFFER_FULL;
+ else
+ return TOR_COMPRESS_OK;
}
#else // HAVE_ZSTD.