diff mbox series

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

Message ID AS1PR01MB9564D33D77D01B46C6ACF1B28F109@AS1PR01MB9564.eurprd01.prod.exchangelabs.com
State Accepted
Commit 93c70b85557a440fe3551cc7bd43b39035e3b970
Headers show
Series [FFmpeg-devel,01/21] avcodec/pngenc: Avoid potentially truncating integers | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt March 15, 2022, 8:05 p.m. UTC
This fixes the problem of potentially closing a z_stream
that has never been successfully initialized.

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

Patch

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)