[tor-commits] [tor/master] Fix handling of "final" flag in zstd decompression

nickm at torproject.org nickm at torproject.org
Thu Apr 27 14:55:26 UTC 2017


commit 39cfaba9e26d1ca0a9b9db3ed2c2e4ba1ff9d533
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Apr 27 10:42:05 2017 -0400

    Fix handling of "final" flag in zstd decompression
    
    We were returning "DONE" on truncated input streams, which was not
    what we wanted.
---
 src/common/compress_zstd.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c
index 9c134fd..99d05c3 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;





More information about the tor-commits mailing list