]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Better error handling when trying to compress/decompress into empty buffer.
authorAlexander Færøy <ahf@torproject.org>
Thu, 28 Sep 2017 14:46:10 +0000 (16:46 +0200)
committerAlexander Færøy <ahf@torproject.org>
Thu, 28 Sep 2017 18:17:41 +0000 (20:17 +0200)
This patch ensures that we return TOR_COMPRESS_BUFFER_FULL in case we
have a input bytes left to process, but are out of output buffer or in
case we need to finish where the compression implementation might need
to write an epilogue.

See: https://bugs.torproject.org/23551

changes/bug23551 [new file with mode: 0644]
src/common/compress.c

diff --git a/changes/bug23551 b/changes/bug23551
new file mode 100644 (file)
index 0000000..2f918bf
--- /dev/null
@@ -0,0 +1,3 @@
+  o Minor bugfixes (compression):
+    - Handle a pathological case when decompressing Zstandard data when the
+      output buffer size is zero. Fixes bug 23551; bugfix on 0.3.1.1-alpha.
index 7926faaa6090794401a8e80e17106c7fc1b5f774..beeff5fcb86ad5e3b07ce4f818f439b8270d5123 100644 (file)
@@ -546,6 +546,13 @@ tor_compress_process(tor_compress_state_t *state,
   const size_t out_len_orig = *out_len;
   tor_compress_output_t rv;
 
+  if (*out_len == 0 && (*in_len > 0 || finish)) {
+    // If we still have input data, but no space for output data, we might as
+    // well return early and let the caller do the reallocation of the out
+    // variable.
+    return TOR_COMPRESS_BUFFER_FULL;
+  }
+
   switch (state->method) {
     case GZIP_METHOD:
     case ZLIB_METHOD: