From 4960c62944fcc85ed09d811fbe4765289effa64a Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Tue, 15 Mar 2022 12:19:37 +0100 Subject: [PATCH] avcodec/mvha: Use ff_inflate_init/end() This fixes the problem of potentially closing a z_stream that has never been successfully initialized. Signed-off-by: Andreas Rheinhardt --- configure | 3 +-- libavcodec/mvha.c | 30 +++++++++++------------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/configure b/configure index 8c89c96de0..ad5f73305a 100755 --- a/configure +++ b/configure @@ -2892,8 +2892,7 @@ msmpeg4v3_encoder_select="h263_encoder" mss2_decoder_select="mpegvideodec qpeldsp vc1_decoder" mts2_decoder_select="jpegtables mss34dsp" mv30_decoder_select="aandcttables blockdsp" -mvha_decoder_deps="zlib" -mvha_decoder_select="llviddsp" +mvha_decoder_select="inflate_wrapper llviddsp" mwsc_decoder_select="inflate_wrapper" mxpeg_decoder_select="mjpeg_decoder" nellymoser_decoder_select="mdct sinewin" diff --git a/libavcodec/mvha.c b/libavcodec/mvha.c index 4048e4625c..05ddcfeb8f 100644 --- a/libavcodec/mvha.c +++ b/libavcodec/mvha.c @@ -32,6 +32,7 @@ #include "get_bits.h" #include "internal.h" #include "lossless_videodsp.h" +#include "zlib_wrapper.h" #include @@ -43,7 +44,7 @@ typedef struct MVHAContext { uint32_t prob[256]; VLC vlc; - z_stream zstream; + FFZStream zstream; LLVidDSPContext llviddsp; } MVHAContext; @@ -168,21 +169,22 @@ static int decode_frame(AVCodecContext *avctx, return ret; if (type == MKTAG('L','Z','Y','V')) { - ret = inflateReset(&s->zstream); + z_stream *const zstream = &s->zstream.zstream; + ret = inflateReset(zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); return AVERROR_EXTERNAL; } - s->zstream.next_in = avpkt->data + 8; - s->zstream.avail_in = avpkt->size - 8; + zstream->next_in = avpkt->data + 8; + zstream->avail_in = avpkt->size - 8; for (int p = 0; p < 3; p++) { for (int y = 0; y < avctx->height; y++) { - s->zstream.next_out = frame->data[p] + (avctx->height - y - 1) * frame->linesize[p]; - s->zstream.avail_out = avctx->width >> (p > 0); + zstream->next_out = frame->data[p] + (avctx->height - y - 1) * frame->linesize[p]; + zstream->avail_out = avctx->width >> (p > 0); - ret = inflate(&s->zstream, Z_SYNC_FLUSH); + ret = inflate(zstream, Z_SYNC_FLUSH); if (ret != Z_OK && ret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", ret); return AVERROR_EXTERNAL; @@ -279,29 +281,19 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_init(AVCodecContext *avctx) { MVHAContext *s = avctx->priv_data; - int zret; avctx->pix_fmt = AV_PIX_FMT_YUV422P; - s->zstream.zalloc = Z_NULL; - s->zstream.zfree = Z_NULL; - s->zstream.opaque = Z_NULL; - zret = inflateInit(&s->zstream); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); - return AVERROR_EXTERNAL; - } - ff_llviddsp_init(&s->llviddsp); - return 0; + return ff_inflate_init(&s->zstream, avctx); } static av_cold int decode_close(AVCodecContext *avctx) { MVHAContext *s = avctx->priv_data; - inflateEnd(&s->zstream); + ff_inflate_end(&s->zstream); ff_free_vlc(&s->vlc); return 0;