History

avfilter/drawtext: make command processing error-resilient

Prevents crash or interruption in text rendering if new option string contains invalid values.

Gyan Doshi committed 7 years ago

Commit 87db1ca1 parent 98478c01 file · +38 −9Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_drawtext.c+38−9
@@ -862,20 +862,49 @@ static int config_input(AVFilterLink *inlink) · 861 unmodified lines
862862
863863 static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
864864 {
865− DrawTextContext *s = ctx->priv;
865+ DrawTextContext *old = ctx->priv;
866+ DrawTextContext *new = NULL;
867+ int ret;
866868
867869 if (!strcmp(cmd, "reinit")) {
868− int ret;
870+ new = av_mallocz(sizeof(DrawTextContext));
871+ if (!new)
872+ return AVERROR(ENOMEM);
873+
874+ new->class = &drawtext_class;
875+ ret = av_opt_copy(new, old);
876+ if (ret < 0)
877+ goto fail;
878+
879+ ctx->priv = new;
880+ ret = av_set_options_string(ctx, arg, "=", ":");
881+ if (ret < 0) {
882+ ctx->priv = old;
883+ goto fail;
884+ }
885+
886+ ret = init(ctx);
887+ if (ret < 0) {
888+ uninit(ctx);
889+ ctx->priv = old;
890+ goto fail;
891+ }
892+
893+ new->reinit = 1;
894+
895+ ctx->priv = old;
869896 uninit(ctx);
870− s->reinit = 1;
871− if ((ret = av_set_options_string(ctx, arg, "=", ":")) < 0)
872− return ret;
873− if ((ret = init(ctx)) < 0)
874− return ret;
897+ av_freep(old);
898+
899+ ctx->priv = new;
875900 return config_input(ctx->inputs[0]);
876− }
901+ } else
902+ return AVERROR(ENOSYS);
877903
878− return AVERROR(ENOSYS);
904+fail:
905+ av_log(ctx, AV_LOG_ERROR, "Failed to process command. Continuing with existing parameters.\n");
906+ av_freep(new);
907+ return ret;
879908 }
880909
881910 static int func_pict_type(AVFilterContext *ctx, AVBPrint *bp,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t