From: Joshua Rogers Date: Fri, 10 Oct 2025 23:15:05 +0000 (+0800) Subject: comp/zstd: fix BIO_CTRL_RESET to properly reset state X-Git-Tag: 4.0-PRE-CLANG-FORMAT-WEBKIT~190 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=573fbe66344734031428a98df40b485bbe4d0dbc;p=thirdparty%2Fopenssl.git comp/zstd: fix BIO_CTRL_RESET to properly reset state 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 Reviewed-by: Saša Nedvědický Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/28844) --- diff --git a/crypto/comp/c_zstd.c b/crypto/comp/c_zstd.c index e9b14472506..193e3d86541 100644 --- a/crypto/comp/c_zstd.c +++ b/crypto/comp/c_zstd.c @@ -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;