summaryrefslogtreecommitdiffstats
path: root/libavfilter/vf_datascope.c
diff options
context:
space:
mode:
authorNil Fons Miret <[email protected]>2025-02-21 01:18:21 +0000
committerMichael Niedermayer <[email protected]>2025-03-11 14:17:01 +0100
commit9899da8175f059aa8bf21e45ad1b5e7cfd33b786 (patch)
tree8fcde38cefed933102af93a7ef2057bcf76497f8 /libavfilter/vf_datascope.c
parentbdc07f372ac14ad9cb6d4f7f356d4c7a47c251fe (diff)
libavfilter: guard against ff_draw_init/ff_draw_init2 failures
The return value of ff_draw_init and ff_draw_init2 are not checked in most usages. However, if they return an error, they don't get to the point where they set the attributes of the FFDrawContext. These functions are typically used in conjunction with ff_draw_color, which checks draw->desc->flags, causing a null pointer dereference. Signed-off-by: Nil Fons Miret <[email protected]> Signed-off-by: Michael Niedermayer <[email protected]>
Diffstat (limited to 'libavfilter/vf_datascope.c')
-rw-r--r--libavfilter/vf_datascope.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/libavfilter/vf_datascope.c b/libavfilter/vf_datascope.c
index 75dc149fbd..6efeb875a6 100644
--- a/libavfilter/vf_datascope.c
+++ b/libavfilter/vf_datascope.c
@@ -382,11 +382,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int config_input(AVFilterLink *inlink)
{
- DatascopeContext *s = inlink->dst->priv;
+ AVFilterContext *ctx = inlink->dst;
+ DatascopeContext *s = ctx->priv;
+
uint8_t alpha = s->opacity * 255;
+ int ret;
s->nb_planes = av_pix_fmt_count_planes(inlink->format);
- ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
+ ret = ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0);
+ if (ret < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
+ return ret;
+ }
ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, alpha} );
ff_draw_color(&s->draw, &s->yellow, (uint8_t[]){ 255, 255, 0, 255} );
@@ -509,10 +516,16 @@ AVFILTER_DEFINE_CLASS(pixscope);
static int pixscope_config_input(AVFilterLink *inlink)
{
- PixscopeContext *s = inlink->dst->priv;
+ AVFilterContext *ctx = inlink->dst;
+ PixscopeContext *s = ctx->priv;
+ int ret;
s->nb_planes = av_pix_fmt_count_planes(inlink->format);
- ff_draw_init(&s->draw, inlink->format, 0);
+ ret = ff_draw_init(&s->draw, inlink->format, 0);
+ if (ret < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
+ return ret;
+ }
ff_draw_color(&s->draw, &s->dark, (uint8_t[]){ 0, 0, 0, s->o * 255} );
ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, 255} );
ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
@@ -927,11 +940,17 @@ static void update_oscilloscope(AVFilterContext *ctx)
static int oscilloscope_config_input(AVFilterLink *inlink)
{
- OscilloscopeContext *s = inlink->dst->priv;
+ AVFilterContext *ctx = inlink->dst;
+ OscilloscopeContext *s = ctx->priv;
int size;
+ int ret;
s->nb_planes = av_pix_fmt_count_planes(inlink->format);
- ff_draw_init(&s->draw, inlink->format, 0);
+ ret = ff_draw_init(&s->draw, inlink->format, 0);
+ if (ret < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n");
+ return ret;
+ }
ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, 255} );
ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} );
ff_draw_color(&s->draw, &s->green, (uint8_t[]){ 0, 255, 0, 255} );