1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-02-04 06:08:26 +02:00

avcodec/wcmv: 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>
This commit is contained in:
Andreas Rheinhardt 2022-03-15 11:33:26 +01:00
parent 93c70b8555
commit c78d39b641
2 changed files with 20 additions and 28 deletions

2
configure vendored
View File

@ -2972,7 +2972,7 @@ vp6f_decoder_select="vp6_decoder"
vp7_decoder_select="h264pred videodsp vp8dsp"
vp8_decoder_select="h264pred videodsp vp8dsp"
vp9_decoder_select="videodsp vp9_parser vp9_superframe_split_bsf"
wcmv_decoder_deps="zlib"
wcmv_decoder_select="inflate_wrapper"
webp_decoder_select="vp8_decoder exif"
wmalossless_decoder_select="llauddsp"
wmapro_decoder_select="mdct sinewin wma_freqs"

View File

@ -29,12 +29,13 @@
#include "avcodec.h"
#include "bytestream.h"
#include "internal.h"
#include "zlib_wrapper.h"
#include <zlib.h>
typedef struct WCMVContext {
int bpp;
z_stream zstream;
FFZStream zstream;
AVFrame *prev_frame;
uint8_t block_data[65536*8];
} WCMVContext;
@ -44,12 +45,13 @@ static int decode_frame(AVCodecContext *avctx,
AVPacket *avpkt)
{
WCMVContext *s = avctx->priv_data;
z_stream *const zstream = &s->zstream.zstream;
AVFrame *frame = data;
int skip, blocks, zret, ret, intra = 0, flags = 0, bpp = s->bpp;
GetByteContext gb;
uint8_t *dst;
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_EXTERNAL;
@ -78,19 +80,19 @@ static int decode_frame(AVCodecContext *avctx,
if (size > avpkt->size - skip)
return AVERROR_INVALIDDATA;
s->zstream.next_in = avpkt->data + skip;
s->zstream.avail_in = size;
s->zstream.next_out = s->block_data;
s->zstream.avail_out = sizeof(s->block_data);
zstream->next_in = avpkt->data + skip;
zstream->avail_in = size;
zstream->next_out = s->block_data;
zstream->avail_out = sizeof(s->block_data);
zret = inflate(&s->zstream, Z_FINISH);
zret = inflate(zstream, Z_FINISH);
if (zret != Z_STREAM_END) {
av_log(avctx, AV_LOG_ERROR,
"Inflate failed with return code: %d.\n", zret);
return AVERROR_INVALIDDATA;
}
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_EXTERNAL;
@ -119,8 +121,8 @@ static int decode_frame(AVCodecContext *avctx,
skip = bytestream2_tell(&gb);
s->zstream.next_in = avpkt->data + skip;
s->zstream.avail_in = avpkt->size - skip;
zstream->next_in = avpkt->data + skip;
zstream->avail_in = avpkt->size - skip;
bytestream2_init(&gb, s->block_data, blocks * 8);
} else if (blocks) {
@ -148,8 +150,8 @@ static int decode_frame(AVCodecContext *avctx,
skip = bytestream2_tell(&gb);
s->zstream.next_in = avpkt->data + skip;
s->zstream.avail_in = avpkt->size - skip;
zstream->next_in = avpkt->data + skip;
zstream->avail_in = avpkt->size - skip;
bytestream2_seek(&gb, 2, SEEK_SET);
}
@ -182,10 +184,10 @@ static int decode_frame(AVCodecContext *avctx,
dst = s->prev_frame->data[0] + (avctx->height - y - 1) * s->prev_frame->linesize[0] + x * bpp;
for (int i = 0; i < h; i++) {
s->zstream.next_out = dst;
s->zstream.avail_out = w * bpp;
zstream->next_out = dst;
zstream->avail_out = w * bpp;
zret = inflate(&s->zstream, Z_SYNC_FLUSH);
zret = inflate(zstream, Z_SYNC_FLUSH);
if (zret != Z_OK && zret != Z_STREAM_END) {
av_log(avctx, AV_LOG_ERROR,
"Inflate failed with return code: %d.\n", zret);
@ -210,7 +212,6 @@ static int decode_frame(AVCodecContext *avctx,
static av_cold int decode_init(AVCodecContext *avctx)
{
WCMVContext *s = avctx->priv_data;
int zret;
switch (avctx->bits_per_coded_sample) {
case 16: avctx->pix_fmt = AV_PIX_FMT_RGB565LE; break;
@ -223,20 +224,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
s->bpp = avctx->bits_per_coded_sample >> 3;
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;
}
s->prev_frame = av_frame_alloc();
if (!s->prev_frame)
return AVERROR(ENOMEM);
return 0;
return ff_inflate_init(&s->zstream, avctx);
}
static av_cold int decode_close(AVCodecContext *avctx)
@ -244,7 +236,7 @@ static av_cold int decode_close(AVCodecContext *avctx)
WCMVContext *s = avctx->priv_data;
av_frame_free(&s->prev_frame);
inflateEnd(&s->zstream);
ff_inflate_end(&s->zstream);
return 0;
}