[FFmpeg-cvslog] avcodec/mscc: Use ff_inflate_init/end()
Andreas Rheinhardt
git at videolan.org
Sat Mar 19 02:30:34 EET 2022
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue Mar 15 12:27:32 2022 +0100| [7fffa718c35d32aa99659524d74f6338247934b6] | committer: Andreas Rheinhardt
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 at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7fffa718c35d32aa99659524d74f6338247934b6
---
configure | 4 ++--
libavcodec/mscc.c | 33 +++++++++++++--------------------
2 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/configure b/configure
index ad5f73305a..0061c54473 100755
--- a/configure
+++ b/configure
@@ -2883,7 +2883,7 @@ mpeg2video_encoder_select="mpegvideoenc h263dsp"
mpeg4_decoder_select="h263_decoder mpeg4video_parser"
mpeg4_encoder_select="h263_encoder"
msa1_decoder_select="mss34dsp"
-mscc_decoder_deps="zlib"
+mscc_decoder_select="inflate_wrapper"
msmpeg4v1_decoder_select="h263_decoder"
msmpeg4v2_decoder_select="h263_decoder"
msmpeg4v2_encoder_select="h263_encoder"
@@ -2935,7 +2935,7 @@ sonic_ls_encoder_select="golomb rangecoder"
sp5x_decoder_select="mjpeg_decoder"
speedhq_decoder_select="mpegvideo"
speedhq_encoder_select="mpegvideoenc"
-srgc_decoder_deps="zlib"
+srgc_decoder_select="inflate_wrapper"
svq1_decoder_select="hpeldsp"
svq1_encoder_select="hpeldsp me_cmp mpegvideoenc"
svq3_decoder_select="golomb h264dsp h264parse h264pred hpeldsp tpeldsp videodsp"
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;
}
More information about the ffmpeg-cvslog
mailing list