[FFmpeg-devel] [PATCH 04/21] avcodec/zerocodec: Use ff_inflate_init/end()

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Mar 15 22:05:54 EET 2022


This fixes the problem of potentially closing a z_stream
that has never been successfully initialized.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 configure              |  2 +-
 libavcodec/zerocodec.c | 21 +++++----------------
 2 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/configure b/configure
index c86e70e985..7c87548359 100755
--- a/configure
+++ b/configure
@@ -2990,7 +2990,7 @@ wmv3image_decoder_select="wmv3_decoder"
 xma1_decoder_select="wmapro_decoder"
 xma2_decoder_select="wmapro_decoder"
 ylc_decoder_select="bswapdsp"
-zerocodec_decoder_deps="zlib"
+zerocodec_decoder_select="inflate_wrapper"
 zlib_decoder_deps="zlib"
 zlib_encoder_deps="zlib"
 zmbv_decoder_select="inflate_wrapper"
diff --git a/libavcodec/zerocodec.c b/libavcodec/zerocodec.c
index 3bd04567a1..86cdf96f5a 100644
--- a/libavcodec/zerocodec.c
+++ b/libavcodec/zerocodec.c
@@ -20,11 +20,12 @@
 
 #include "avcodec.h"
 #include "internal.h"
+#include "zlib_wrapper.h"
 #include "libavutil/common.h"
 
 typedef struct ZeroCodecContext {
     AVFrame  *previous_frame;
-    z_stream zstream;
+    FFZStream zstream;
 } ZeroCodecContext;
 
 static int zerocodec_decode_frame(AVCodecContext *avctx, void *data,
@@ -33,7 +34,7 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, void *data,
     ZeroCodecContext *zc = avctx->priv_data;
     AVFrame *pic         = data;
     AVFrame *prev_pic    = zc->previous_frame;
-    z_stream *zstream    = &zc->zstream;
+    z_stream *const zstream = &zc->zstream.zstream;
     uint8_t *prev        = prev_pic->data[0];
     uint8_t *dst;
     int i, j, zret, ret;
@@ -106,7 +107,7 @@ static av_cold int zerocodec_decode_close(AVCodecContext *avctx)
 
     av_frame_free(&zc->previous_frame);
 
-    inflateEnd(&zc->zstream);
+    ff_inflate_end(&zc->zstream);
 
     return 0;
 }
@@ -114,27 +115,15 @@ static av_cold int zerocodec_decode_close(AVCodecContext *avctx)
 static av_cold int zerocodec_decode_init(AVCodecContext *avctx)
 {
     ZeroCodecContext *zc = avctx->priv_data;
-    z_stream *zstream    = &zc->zstream;
-    int zret;
 
     avctx->pix_fmt             = AV_PIX_FMT_UYVY422;
     avctx->bits_per_raw_sample = 8;
 
-    zstream->zalloc = Z_NULL;
-    zstream->zfree  = Z_NULL;
-    zstream->opaque = Z_NULL;
-
-    zret = inflateInit(zstream);
-    if (zret != Z_OK) {
-        av_log(avctx, AV_LOG_ERROR, "Could not initialize inflate: %d.\n", zret);
-        return AVERROR(ENOMEM);
-    }
-
     zc->previous_frame = av_frame_alloc();
     if (!zc->previous_frame)
         return AVERROR(ENOMEM);
 
-    return 0;
+    return ff_inflate_init(&zc->zstream, avctx);
 }
 
 static void zerocodec_decode_flush(AVCodecContext *avctx)
-- 
2.32.0



More information about the ffmpeg-devel mailing list