提交 37f4a093 编写于 作者: J James Almer

avcodec/vp9_superframe_bsf: allocate cache of packets during init

Also use av_packet_move_ref() to cache them instead of copying
pointers.

Fixes invalid reads since e1bc3f43.
Signed-off-by: NJames Almer <jamrial@gmail.com>
上级 88c7aa13
...@@ -147,8 +147,8 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *out) ...@@ -147,8 +147,8 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *out)
goto done; goto done;
} }
s->cache[s->n_cache++] = in; av_packet_move_ref(s->cache[s->n_cache++], in);
in = NULL;
if (invisible) { if (invisible) {
res = AVERROR(EAGAIN); res = AVERROR(EAGAIN);
goto done; goto done;
...@@ -164,7 +164,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *out) ...@@ -164,7 +164,7 @@ static int vp9_superframe_filter(AVBSFContext *ctx, AVPacket *out)
goto done; goto done;
for (n = 0; n < s->n_cache; n++) for (n = 0; n < s->n_cache; n++)
av_packet_free(&s->cache[n]); av_packet_unref(s->cache[n]);
s->n_cache = 0; s->n_cache = 0;
done: done:
...@@ -174,13 +174,28 @@ done: ...@@ -174,13 +174,28 @@ done:
return res; return res;
} }
static int vp9_superframe_init(AVBSFContext *ctx)
{
VP9BSFContext *s = ctx->priv_data;
int n;
// alloc cached data
for (n = 0; n < MAX_CACHE; n++) {
s->cache[n] = av_packet_alloc();
if (!s->cache[n])
return AVERROR(ENOMEM);
}
return 0;
}
static void vp9_superframe_close(AVBSFContext *ctx) static void vp9_superframe_close(AVBSFContext *ctx)
{ {
VP9BSFContext *s = ctx->priv_data; VP9BSFContext *s = ctx->priv_data;
int n; int n;
// free cached data // free cached data
for (n = 0; n < s->n_cache; n++) for (n = 0; n < MAX_CACHE; n++)
av_packet_free(&s->cache[n]); av_packet_free(&s->cache[n]);
} }
...@@ -192,6 +207,7 @@ const AVBitStreamFilter ff_vp9_superframe_bsf = { ...@@ -192,6 +207,7 @@ const AVBitStreamFilter ff_vp9_superframe_bsf = {
.name = "vp9_superframe", .name = "vp9_superframe",
.priv_data_size = sizeof(VP9BSFContext), .priv_data_size = sizeof(VP9BSFContext),
.filter = vp9_superframe_filter, .filter = vp9_superframe_filter,
.init = vp9_superframe_init,
.close = vp9_superframe_close, .close = vp9_superframe_close,
.codec_ids = codec_ids, .codec_ids = codec_ids,
}; };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册