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.
Unified · Split
| @@ -636,11 +636,20 @@ static int qrencodesrc_config_props(AVFilterLink *outlink) · 635 unmodified lines | ||
| 636 | 636 | return AVERROR(EINVAL); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | − ff_draw_init(&qr->draw, AV_PIX_FMT_ARGB, FF_DRAW_PROCESS_ALPHA); | |
| 639 | + ret = ff_draw_init(&qr->draw, AV_PIX_FMT_ARGB, FF_DRAW_PROCESS_ALPHA); | |
| 640 | + if (ret < 0) { | |
| 641 | + // This call using constants should not fail. Checking its error code for completeness. | |
| 642 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 643 | + return ret; | |
| 644 | + } | |
| 640 | 645 | ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color); |
| 641 | 646 | ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color); |
| 642 | 647 | |
| 643 | − ff_draw_init2(&qr->draw0, outlink->format, outlink->colorspace, outlink->color_range, FF_DRAW_PROCESS_ALPHA); | |
| 648 | + ret = ff_draw_init2(&qr->draw0, outlink->format, outlink->colorspace, outlink->color_range, FF_DRAW_PROCESS_ALPHA); | |
| 649 | + if (ret < 0) { | |
| 650 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 651 | + return ret; | |
| 652 | + } | |
| 644 | 653 | ff_draw_color(&qr->draw0, &qr->draw0_background_color, (const uint8_t *)&qr->background_color); |
| 645 | 654 | |
| 646 | 655 | outlink->w = qr->rendered_padded_qrcode_width; |
| @@ -734,8 +743,12 @@ static int qrencode_config_input(AVFilterLink *inlink) · 87 unmodified lines | ||
| 734 | 743 | |
| 735 | 744 | qr->is_source = 0; |
| 736 | 745 | |
| 737 | − ff_draw_init2(&qr->draw, inlink->format, inlink->colorspace, inlink->color_range, | |
| 738 | − FF_DRAW_PROCESS_ALPHA); | |
| 746 | + ret = ff_draw_init2(&qr->draw, inlink->format, inlink->colorspace, inlink->color_range, | |
| 747 | + FF_DRAW_PROCESS_ALPHA); | |
| 748 | + if (ret < 0) { | |
| 749 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 750 | + return ret; | |
| 751 | + } | |
| 739 | 752 | |
| 740 | 753 | V(W) = V(main_w) = inlink->w; |
| 741 | 754 | V(H) = V(main_h) = inlink->h; |
| @@ -764,8 +777,12 @@ static int qrencode_config_input(AVFilterLink *inlink) · 22 unmodified lines | ||
| 764 | 777 | PARSE_EXPR(rendered_qrcode_width); |
| 765 | 778 | PARSE_EXPR(rendered_padded_qrcode_width); |
| 766 | 779 | |
| 767 | − ff_draw_init2(&qr->draw, inlink->format, inlink->colorspace, inlink->color_range, | |
| 780 | + ret = ff_draw_init2(&qr->draw, inlink->format, inlink->colorspace, inlink->color_range, | |
| 768 | 781 | FF_DRAW_PROCESS_ALPHA); |
| 782 | + if (ret < 0) { | |
| 783 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 784 | + return ret; | |
| 785 | + } | |
| 769 | 786 | ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color); |
| 770 | 787 | ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color); |
| 771 | 788 | |
| @@ -147,6 +147,7 @@ static av_cold int config_props(AVFilterLink *outlink) · 146 unmodified lines | ||
| 147 | 147 | FilterLink *l = ff_filter_link(outlink); |
| 148 | 148 | AVFilterContext *ctx = outlink->src; |
| 149 | 149 | AVSyncTestContext *s = ctx->priv; |
| 150 | + int ret; | |
| 150 | 151 | |
| 151 | 152 | outlink->w = s->w; |
| 152 | 153 | outlink->h = s->h; |
| @@ -160,7 +161,11 @@ static av_cold int config_props(AVFilterLink *outlink) · 7 unmodified lines | ||
| 160 | 161 | s->dir = 1; |
| 161 | 162 | s->prev_intpart = INT64_MIN; |
| 162 | 163 | |
| 163 | − ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0); | |
| 164 | + ret = ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0); | |
| 165 | + if (ret < 0) { | |
| 166 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 167 | + return ret; | |
| 168 | + } | |
| 164 | 169 | |
| 165 | 170 | ff_draw_color(&s->draw, &s->fg, s->rgba[0]); |
| 166 | 171 | ff_draw_color(&s->draw, &s->bg, s->rgba[1]); |
| @@ -382,11 +382,18 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 381 unmodified lines | ||
| 382 | 382 | |
| 383 | 383 | static int config_input(AVFilterLink *inlink) |
| 384 | 384 | { |
| 385 | − DatascopeContext *s = inlink->dst->priv; | |
| 385 | + AVFilterContext *ctx = inlink->dst; | |
| 386 | + DatascopeContext *s = ctx->priv; | |
| 387 | + | |
| 386 | 388 | uint8_t alpha = s->opacity * 255; |
| 389 | + int ret; | |
| 387 | 390 | |
| 388 | 391 | s->nb_planes = av_pix_fmt_count_planes(inlink->format); |
| 389 | − ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 392 | + ret = ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 393 | + if (ret < 0) { | |
| 394 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 395 | + return ret; | |
| 396 | + } | |
| 390 | 397 | ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} ); |
| 391 | 398 | ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, alpha} ); |
| 392 | 399 | ff_draw_color(&s->draw, &s->yellow, (uint8_t[]){ 255, 255, 0, 255} ); |
| @@ -509,10 +516,16 @@ AVFILTER_DEFINE_CLASS(pixscope); · 116 unmodified lines | ||
| 509 | 516 | |
| 510 | 517 | static int pixscope_config_input(AVFilterLink *inlink) |
| 511 | 518 | { |
| 512 | − PixscopeContext *s = inlink->dst->priv; | |
| 519 | + AVFilterContext *ctx = inlink->dst; | |
| 520 | + PixscopeContext *s = ctx->priv; | |
| 521 | + int ret; | |
| 513 | 522 | |
| 514 | 523 | s->nb_planes = av_pix_fmt_count_planes(inlink->format); |
| 515 | − ff_draw_init(&s->draw, inlink->format, 0); | |
| 524 | + ret = ff_draw_init(&s->draw, inlink->format, 0); | |
| 525 | + if (ret < 0) { | |
| 526 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 527 | + return ret; | |
| 528 | + } | |
| 516 | 529 | ff_draw_color(&s->draw, &s->dark, (uint8_t[]){ 0, 0, 0, s->o * 255} ); |
| 517 | 530 | ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, 255} ); |
| 518 | 531 | ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} ); |
| @@ -927,11 +940,17 @@ static void update_oscilloscope(AVFilterContext *ctx) · 408 unmodified lines | ||
| 927 | 940 | |
| 928 | 941 | static int oscilloscope_config_input(AVFilterLink *inlink) |
| 929 | 942 | { |
| 930 | − OscilloscopeContext *s = inlink->dst->priv; | |
| 943 | + AVFilterContext *ctx = inlink->dst; | |
| 944 | + OscilloscopeContext *s = ctx->priv; | |
| 931 | 945 | int size; |
| 946 | + int ret; | |
| 932 | 947 | |
| 933 | 948 | s->nb_planes = av_pix_fmt_count_planes(inlink->format); |
| 934 | − ff_draw_init(&s->draw, inlink->format, 0); | |
| 949 | + ret = ff_draw_init(&s->draw, inlink->format, 0); | |
| 950 | + if (ret < 0) { | |
| 951 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 952 | + return ret; | |
| 953 | + } | |
| 935 | 954 | ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, 255} ); |
| 936 | 955 | ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} ); |
| 937 | 956 | ff_draw_color(&s->draw, &s->green, (uint8_t[]){ 0, 255, 0, 255} ); |
| @@ -1156,7 +1156,11 @@ static int config_input(AVFilterLink *inlink) · 1155 unmodified lines | ||
| 1156 | 1156 | char *expr; |
| 1157 | 1157 | int ret; |
| 1158 | 1158 | |
| 1159 | − ff_draw_init2(&s->dc, inlink->format, inlink->colorspace, inlink->color_range, FF_DRAW_PROCESS_ALPHA); | |
| 1159 | + ret = ff_draw_init2(&s->dc, inlink->format, inlink->colorspace, inlink->color_range, FF_DRAW_PROCESS_ALPHA); | |
| 1160 | + if (ret < 0) { | |
| 1161 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 1162 | + return ret; | |
| 1163 | + } | |
| 1160 | 1164 | ff_draw_color(&s->dc, &s->fontcolor, s->fontcolor.rgba); |
| 1161 | 1165 | ff_draw_color(&s->dc, &s->shadowcolor, s->shadowcolor.rgba); |
| 1162 | 1166 | ff_draw_color(&s->dc, &s->bordercolor, s->bordercolor.rgba); |
| @@ -114,7 +114,11 @@ static int config_input(AVFilterLink *inlink) · 113 unmodified lines | ||
| 114 | 114 | double var_values[VARS_NB], res; |
| 115 | 115 | char *expr; |
| 116 | 116 | |
| 117 | − ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 117 | + ret = ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 118 | + if (ret < 0) { | |
| 119 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 120 | + return ret; | |
| 121 | + } | |
| 118 | 122 | ff_draw_color(&s->draw, &s->color, s->rgba_color); |
| 119 | 123 | |
| 120 | 124 | var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; |
| @@ -250,6 +250,7 @@ static int config_output(AVFilterLink *outlink) · 249 unmodified lines | ||
| 250 | 250 | AVFilterContext *ctx = outlink->src; |
| 251 | 251 | ShearContext *s = ctx->priv; |
| 252 | 252 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format); |
| 253 | + int ret; | |
| 253 | 254 | |
| 254 | 255 | s->nb_planes = av_pix_fmt_count_planes(outlink->format); |
| 255 | 256 | s->depth = desc->comp[0].depth; |
| @@ -260,7 +261,11 @@ static int config_output(AVFilterLink *outlink) · 4 unmodified lines | ||
| 260 | 261 | s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(ctx->inputs[0]->h, desc->log2_chroma_h); |
| 261 | 262 | s->planeheight[0] = s->planeheight[3] = ctx->inputs[0]->h; |
| 262 | 263 | |
| 263 | − ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0); | |
| 264 | + ret = ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0); | |
| 265 | + if (ret < 0) { | |
| 266 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 267 | + return ret; | |
| 268 | + } | |
| 264 | 269 | ff_draw_color(&s->draw, &s->color, s->fillcolor); |
| 265 | 270 | |
| 266 | 271 | s->filter_slice[0] = s->depth <= 8 ? filter_slice_nn8 : filter_slice_nn16; |
| @@ -312,7 +312,11 @@ static int config_output(AVFilterLink *outlink) · 311 unmodified lines | ||
| 312 | 312 | |
| 313 | 313 | if (s->fillcolor_enable) { |
| 314 | 314 | const AVFilterLink *inlink = ctx->inputs[0]; |
| 315 | − ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 315 | + ret = ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 316 | + if (ret < 0) { | |
| 317 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 318 | + return ret; | |
| 319 | + } | |
| 316 | 320 | ff_draw_color(&s->draw, &s->color, s->fillcolor); |
| 317 | 321 | } |
| 318 | 322 | |
| @@ -182,12 +182,18 @@ static int query_formats(const AVFilterContext *ctx, · 181 unmodified lines | ||
| 182 | 182 | |
| 183 | 183 | static int config_input(AVFilterLink *inlink) |
| 184 | 184 | { |
| 185 | − AssContext *ass = inlink->dst->priv; | |
| 185 | + AVFilterContext *ctx = inlink->dst; | |
| 186 | + AssContext *ass = ctx->priv; | |
| 187 | + int ret; | |
| 186 | 188 | |
| 187 | − ff_draw_init2(&ass->draw, inlink->format, | |
| 188 | − ass_get_color_space(ass->track->YCbCrMatrix, inlink->colorspace), | |
| 189 | − ass_get_color_range(ass->track->YCbCrMatrix, inlink->color_range), | |
| 190 | − ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0); | |
| 189 | + ret = ff_draw_init2(&ass->draw, inlink->format, | |
| 190 | + ass_get_color_space(ass->track->YCbCrMatrix, inlink->colorspace), | |
| 191 | + ass_get_color_range(ass->track->YCbCrMatrix, inlink->color_range), | |
| 192 | + ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0); | |
| 193 | + if (ret < 0) { | |
| 194 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 195 | + return ret; | |
| 196 | + } | |
| 191 | 197 | |
| 192 | 198 | ass_set_frame_size (ass->renderer, inlink->w, inlink->h); |
| 193 | 199 | if (ass->original_w && ass->original_h) { |
| @@ -128,6 +128,7 @@ static int config_props(AVFilterLink *outlink) · 127 unmodified lines | ||
| 128 | 128 | FilterLink *ol = ff_filter_link(outlink); |
| 129 | 129 | const unsigned total_margin_w = (tile->w - 1) * tile->padding + 2*tile->margin; |
| 130 | 130 | const unsigned total_margin_h = (tile->h - 1) * tile->padding + 2*tile->margin; |
| 131 | + int ret; | |
| 131 | 132 | |
| 132 | 133 | if (inlink->w > (INT_MAX - total_margin_w) / tile->w) { |
| 133 | 134 | av_log(ctx, AV_LOG_ERROR, "Total width %ux%u is too much.\n", |
| @@ -143,7 +144,11 @@ static int config_props(AVFilterLink *outlink) · 9 unmodified lines | ||
| 143 | 144 | outlink->h = tile->h * inlink->h + total_margin_h; |
| 144 | 145 | outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; |
| 145 | 146 | ol->frame_rate = av_mul_q(il->frame_rate, av_make_q(1, tile->nb_frames - tile->overlap)); |
| 146 | − ff_draw_init2(&tile->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 147 | + ret = ff_draw_init2(&tile->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 148 | + if (ret < 0) { | |
| 149 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 150 | + return ret; | |
| 151 | + } | |
| 147 | 152 | ff_draw_color(&tile->draw, &tile->blank, tile->rgba_color); |
| 148 | 153 | |
| 149 | 154 | return 0; |
| @@ -228,7 +228,11 @@ static int config_out_props(AVFilterLink *outlink) · 227 unmodified lines | ||
| 228 | 228 | |
| 229 | 229 | if (tinterlace->mode == MODE_PAD) { |
| 230 | 230 | uint8_t black[4] = { 0, 0, 0, 16 }; |
| 231 | − ff_draw_init2(&tinterlace->draw, outlink->format, outlink->colorspace, outlink->color_range, 0); | |
| 231 | + ret = ff_draw_init2(&tinterlace->draw, outlink->format, outlink->colorspace, outlink->color_range, 0); | |
| 232 | + if (ret < 0) { | |
| 233 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 234 | + return ret; | |
| 235 | + } | |
| 232 | 236 | ff_draw_color(&tinterlace->draw, &tinterlace->color, black); |
| 233 | 237 | /* limited range */ |
| 234 | 238 | if (!ff_fmt_is_in(outlink->format, full_scale_yuvj_pix_fmts)) { |
| @@ -206,9 +206,14 @@ static int config_input(AVFilterLink *inlink) · 205 unmodified lines | ||
| 206 | 206 | AVFilterContext *ctx = inlink->dst; |
| 207 | 207 | FilterLink *l = ff_filter_link(inlink); |
| 208 | 208 | TPadContext *s = ctx->priv; |
| 209 | + int ret; | |
| 209 | 210 | |
| 210 | 211 | if (needs_drawing(s)) { |
| 211 | − ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 212 | + ret = ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); | |
| 213 | + if (ret < 0) { | |
| 214 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 215 | + return ret; | |
| 216 | + } | |
| 212 | 217 | ff_draw_color(&s->draw, &s->color, s->rgba_color); |
| 213 | 218 | } |
| 214 | 219 | |
| @@ -262,8 +262,13 @@ static int color_config_props(AVFilterLink *inlink) · 261 unmodified lines | ||
| 262 | 262 | TestSourceContext *test = ctx->priv; |
| 263 | 263 | int ret; |
| 264 | 264 | |
| 265 | − ff_draw_init2(&test->draw, inlink->format, inlink->colorspace, | |
| 266 | − inlink->color_range, 0); | |
| 265 | + ret = ff_draw_init2(&test->draw, inlink->format, inlink->colorspace, | |
| 266 | + inlink->color_range, 0); | |
| 267 | + if (ret < 0) { | |
| 268 | + av_log(ctx, AV_LOG_ERROR, "Failed to initialize FFDrawContext\n"); | |
| 269 | + return ret; | |
| 270 | + } | |
| 271 | + | |
| 267 | 272 | ff_draw_color(&test->draw, &test->color, test->color_rgba); |
| 268 | 273 | |
| 269 | 274 | if (av_image_check_size(test->w, test->h, 0, ctx) < 0) |