zstd: Check errors right affer compressing/decompressing

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>
This commit is contained in:
David Goulet
2023-08-14 11:03:47 -04:00
parent 78cb761612
commit fd3f9e8580
2 changed files with 13 additions and 7 deletions
+7 -7
View 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);