1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-15 14:13:16 +02:00

avcodec/vbn(dec|enc): Avoid leaving stale pointers in context

Therefore move the (Get|Put)ByteContext from the context to the stack.
It is transient anyway.

Reviewed-by: Marton Balint <cus@passwd.hu>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2022-04-12 19:17:08 +02:00
parent 81b6a10937
commit 300dd79c3d
2 changed files with 5 additions and 9 deletions

View File

@@ -34,7 +34,6 @@
typedef struct VBNContext { typedef struct VBNContext {
TextureDSPContext texdsp; TextureDSPContext texdsp;
TextureDSPThreadContext dec; TextureDSPThreadContext dec;
GetByteContext gb;
} VBNContext; } VBNContext;
static av_cold int vbn_init(AVCodecContext *avctx) static av_cold int vbn_init(AVCodecContext *avctx)
@@ -44,11 +43,9 @@ static av_cold int vbn_init(AVCodecContext *avctx)
return 0; return 0;
} }
static int decompress(AVCodecContext *avctx, int compression, uint8_t **outbuf) static int decompress(AVCodecContext *avctx, GetByteContext *gb,
int compression, uint8_t **outbuf)
{ {
VBNContext *ctx = avctx->priv_data;
GetByteContext *gb = &ctx->gb;
if (compression == VBN_COMPRESSION_NONE) // outbuf is left NULL because gb->buf can be used directly if (compression == VBN_COMPRESSION_NONE) // outbuf is left NULL because gb->buf can be used directly
return bytestream2_get_bytes_left(gb); return bytestream2_get_bytes_left(gb);
@@ -61,7 +58,7 @@ static int vbn_decode_frame(AVCodecContext *avctx,
AVPacket *avpkt) AVPacket *avpkt)
{ {
VBNContext *ctx = avctx->priv_data; VBNContext *ctx = avctx->priv_data;
GetByteContext *gb = &ctx->gb; GetByteContext gb0, *const gb = &gb0;
uint8_t *image_buf = NULL; uint8_t *image_buf = NULL;
int image_len; int image_len;
int width, height, components, format, compression, pix_fmt, linesize, data_size; int width, height, components, format, compression, pix_fmt, linesize, data_size;
@@ -139,7 +136,7 @@ static int vbn_decode_frame(AVCodecContext *avctx,
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
} }
image_len = decompress(avctx, compression, &image_buf); image_len = decompress(avctx, gb, compression, &image_buf);
if (image_len < 0) if (image_len < 0)
return image_len; return image_len;

View File

@@ -37,7 +37,6 @@
typedef struct VBNContext { typedef struct VBNContext {
AVClass *class; AVClass *class;
TextureDSPContext dxtc; TextureDSPContext dxtc;
PutByteContext pb;
int format; int format;
TextureDSPThreadContext enc; TextureDSPThreadContext enc;
} VBNContext; } VBNContext;
@@ -46,7 +45,7 @@ static int vbn_encode(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet) const AVFrame *frame, int *got_packet)
{ {
VBNContext *ctx = avctx->priv_data; VBNContext *ctx = avctx->priv_data;
PutByteContext *pb = &ctx->pb; PutByteContext pb0, *const pb = &pb0;
int ret; int ret;
ptrdiff_t linesize; ptrdiff_t linesize;
int64_t pkt_size; int64_t pkt_size;