diff options
author | teor <teor2345@gmail.com> | 2017-06-16 09:47:32 +1000 |
---|---|---|
committer | teor <teor2345@gmail.com> | 2017-06-16 09:47:32 +1000 |
commit | cbaf0c049c8a73a7bbd2e8bf574589f84f99ccd8 (patch) | |
tree | e90820af509f0f20ead12ee4020658ab9022e0ad /src/common/compress_zstd.c | |
parent | 617e1da63655a90dba499e8fe11263d3331aacf7 (diff) | |
download | tor-cbaf0c049c8a73a7bbd2e8bf574589f84f99ccd8.tar.gz tor-cbaf0c049c8a73a7bbd2e8bf574589f84f99ccd8.zip |
Return TOR_COMPRESS_BUFFER_FULL when zstd has additional input
Fixes #22628.
Diffstat (limited to 'src/common/compress_zstd.c')
-rw-r--r-- | src/common/compress_zstd.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c index 11fcf86644..a136db48bf 100644 --- a/src/common/compress_zstd.c +++ b/src/common/compress_zstd.c @@ -340,8 +340,20 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state, return TOR_COMPRESS_BUFFER_FULL; return TOR_COMPRESS_DONE; - } else { - return (retval == 0) ? TOR_COMPRESS_DONE : TOR_COMPRESS_OK; + } else /* if (!state->compress) */ { + // ZSTD_decompressStream returns 0 if the frame is done, or >0 if it + // is incomplete. + // 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. |