]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
comp/zstd: fix BIO_CTRL_RESET to properly reset state
authorJoshua Rogers <MegaManSec@users.noreply.github.com>
Fri, 10 Oct 2025 23:15:05 +0000 (07:15 +0800)
committerTomas Mraz <tomas@openssl.org>
Tue, 18 Nov 2025 16:46:24 +0000 (17:46 +0100)
BIO_CTRL_RESET zeroed compress.bufsize and did not reinitialize the ZSTD
streams or buffer positions. After a reset, the next write could try to use
a 0 byte buffer and stall or behave unpredictably.

Signed-off-by: Joshua Rogers <MegaManSec@users.noreply.github.com>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28844)

crypto/comp/c_zstd.c

index e9b14472506d0fb4e36003ca1b414a767328a53d..193e3d865411d2c15e8016189a060f85ff405115 100644 (file)
@@ -759,8 +759,19 @@ static long bio_zstd_ctrl(BIO *b, int cmd, long num, void *ptr)
     switch (cmd) {
 
     case BIO_CTRL_RESET:
+        /* reset decompressor */
+        ctx->decompress.inbuf.size = 0;
+        ctx->decompress.inbuf.pos = 0;
+        if (ctx->decompress.state != NULL)
+            ZSTD_initDStream(ctx->decompress.state);
+
+        /* reset compressor */
         ctx->compress.write_pos = 0;
-        ctx->compress.bufsize = 0;
+        ctx->compress.outbuf.pos = 0;
+        if (ctx->compress.state != NULL)
+            ZSTD_initCStream(ctx->compress.state, ZSTD_CLEVEL_DEFAULT);
+
+        /* keep existing bufsize, do not set it to 0 */
         ret = 1;
         break;