diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-03-15 12:27:32 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-03-19 00:18:35 +0100 |
commit | 7fffa718c35d32aa99659524d74f6338247934b6 (patch) | |
tree | c0f1d64c1be0801efec0eef4a51b74559b14774c /libavcodec | |
parent | 4960c62944fcc85ed09d811fbe4765289effa64a (diff) | |
download | ffmpeg-7fffa718c35d32aa99659524d74f6338247934b6.tar.gz |
avcodec/mscc: 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/mscc.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/libavcodec/mscc.c b/libavcodec/mscc.c index d9a6de094a..19cfce796e 100644 --- a/libavcodec/mscc.c +++ b/libavcodec/mscc.c @@ -27,6 +27,7 @@ #include "avcodec.h" #include "bytestream.h" #include "internal.h" +#include "zlib_wrapper.h" #include <zlib.h> @@ -36,7 +37,7 @@ typedef struct MSCCContext { uint8_t *decomp_buf; unsigned int uncomp_size; uint8_t *uncomp_buf; - z_stream zstream; + FFZStream zstream; uint32_t pal[256]; } MSCCContext; @@ -132,6 +133,7 @@ static int decode_frame(AVCodecContext *avctx, AVPacket *avpkt) { MSCCContext *s = avctx->priv_data; + z_stream *const zstream = &s->zstream.zstream; AVFrame *frame = data; uint8_t *buf = avpkt->data; int buf_size = avpkt->size; @@ -166,22 +168,22 @@ static int decode_frame(AVCodecContext *avctx, memcpy(frame->data[1], s->pal, AVPALETTE_SIZE); } - ret = inflateReset(&s->zstream); + ret = inflateReset(zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); return AVERROR_UNKNOWN; } - s->zstream.next_in = buf; - s->zstream.avail_in = buf_size; - s->zstream.next_out = s->decomp_buf; - s->zstream.avail_out = s->decomp_size; - ret = inflate(&s->zstream, Z_FINISH); + zstream->next_in = buf; + zstream->avail_in = buf_size; + zstream->next_out = s->decomp_buf; + zstream->avail_out = s->decomp_size; + ret = inflate(zstream, Z_FINISH); if (ret != Z_STREAM_END) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", ret); return AVERROR_UNKNOWN; } - bytestream2_init(&gb, s->decomp_buf, s->zstream.total_out); + bytestream2_init(&gb, s->decomp_buf, zstream->total_out); bytestream2_init_writer(&pb, s->uncomp_buf, s->uncomp_size); ret = rle_uncompress(avctx, &gb, &pb); @@ -204,7 +206,7 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_init(AVCodecContext *avctx) { MSCCContext *s = avctx->priv_data; - int stride, zret; + int stride; switch (avctx->bits_per_coded_sample) { case 8: avctx->pix_fmt = AV_PIX_FMT_PAL8; break; @@ -227,16 +229,7 @@ static av_cold int decode_init(AVCodecContext *avctx) if (!(s->uncomp_buf = av_malloc(s->uncomp_size))) return AVERROR(ENOMEM); - 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_UNKNOWN; - } - - return 0; + return ff_inflate_init(&s->zstream, avctx); } static av_cold int decode_close(AVCodecContext *avctx) @@ -247,7 +240,7 @@ static av_cold int decode_close(AVCodecContext *avctx) s->decomp_size = 0; av_freep(&s->uncomp_buf); s->uncomp_size = 0; - inflateEnd(&s->zstream); + ff_inflate_end(&s->zstream); return 0; } |