diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-04-27 10:42:05 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-04-27 10:42:05 -0400 |
commit | 39cfaba9e26d1ca0a9b9db3ed2c2e4ba1ff9d533 (patch) | |
tree | 5e6a388ff57666c4feb7361c9c32a68fd192861f /src | |
parent | 166aa8d7416989aa0f5e3169a0f08a1d1bea619d (diff) | |
download | tor-39cfaba9e26d1ca0a9b9db3ed2c2e4ba1ff9d533.tar.gz tor-39cfaba9e26d1ca0a9b9db3ed2c2e4ba1ff9d533.zip |
Fix handling of "final" flag in zstd decompression
We were returning "DONE" on truncated input streams, which was not
what we wanted.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/compress_zstd.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c index 9c134fdf4e..99d05c37bd 100644 --- a/src/common/compress_zstd.c +++ b/src/common/compress_zstd.c @@ -316,7 +316,10 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state, return TOR_COMPRESS_BUFFER_FULL; } - if (state->compress && finish) { + if (!finish) { + // We're not done with the input, so no need to flush. + return TOR_COMPRESS_OK; + } else if (state->compress && finish) { retval = ZSTD_endStream(state->u.compress_stream, &output); *out = (char *)output.dst + output.pos; @@ -333,9 +336,14 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state, // epilogue. if (retval > 0) return TOR_COMPRESS_BUFFER_FULL; + + return TOR_COMPRESS_DONE; + } else { + // ZSTD_flushStream returns 0 if the frame is done, or >0 if it + // is incomplete. + return (retval == 0) ? TOR_COMPRESS_DONE : TOR_COMPRESS_OK; } - return finish ? TOR_COMPRESS_DONE : TOR_COMPRESS_OK; #else // HAVE_ZSTD. (void)state; (void)out; |