]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
zstd: Check errors right affer compressing/decompressing
authorDavid Goulet <dgoulet@torproject.org>
Mon, 14 Aug 2023 15:03:47 +0000 (11:03 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Mon, 14 Aug 2023 15:05:23 +0000 (11:05 -0400)
Considering a compression bomb before looking for errors led to false negative
log warnings. Instead, it is possible the work failed for whatever reasons
which is not indicative of a compression bomb.

Fixes #40739

Signed-off-by: David Goulet <dgoulet@torproject.org>
changes/ticket40739 [new file with mode: 0644]
src/lib/compress/compress_zstd.c

diff --git a/changes/ticket40739 b/changes/ticket40739
new file mode 100644 (file)
index 0000000..d65c143
--- /dev/null
@@ -0,0 +1,6 @@
+  o Minor bugfixes (compression):
+    - Right after compression/decompression work is done, check for errors.
+      Before this, we would consider compression bomb before that and then
+      looking for errors leading to false positive on that log warning. Fixes
+      bug 40739; bugfix on 0.3.5.1-alpha. Patch by "cypherpunks".
+
index 34a2e806f6153901a31f54807c209318df0241e7..85c2bb3bfacc8b06aca3c84240d7a8676e3a7e3a 100644 (file)
@@ -368,6 +368,13 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
                                    &output, &input);
   }
 
+  if (ZSTD_isError(retval)) {
+    log_warn(LD_GENERAL, "Zstandard %s didn't finish: %s.",
+             state->compress ? "compression" : "decompression",
+             ZSTD_getErrorName(retval));
+    return TOR_COMPRESS_ERROR;
+  }
+
   state->input_so_far += input.pos;
   state->output_so_far += output.pos;
 
@@ -383,13 +390,6 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
     return TOR_COMPRESS_ERROR;
   }
 
-  if (ZSTD_isError(retval)) {
-    log_warn(LD_GENERAL, "Zstandard %s didn't finish: %s.",
-             state->compress ? "compression" : "decompression",
-             ZSTD_getErrorName(retval));
-    return TOR_COMPRESS_ERROR;
-  }
-
   if (state->compress && !state->have_called_end) {
     retval = ZSTD_flushStream(state->u.compress_stream, &output);