diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-03-15 12:19:37 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-03-19 00:18:35 +0100 |
commit | 4960c62944fcc85ed09d811fbe4765289effa64a (patch) | |
tree | 380fe30d157d34c6d0993cfa712c2defdefe7ec4 /libavcodec | |
parent | c1b0b8f9beec02e616366376f540d7ea3f941347 (diff) | |
download | ffmpeg-4960c62944fcc85ed09d811fbe4765289effa64a.tar.gz |
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 <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/mvha.c | 30 |
1 files changed, 11 insertions, 19 deletions
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 <zlib.h> @@ -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; |