diff options
author | Gyan Doshi <ffmpeg@gyani.pro> | 2019-05-10 19:13:33 +0530 |
---|---|---|
committer | Gyan Doshi <ffmpeg@gyani.pro> | 2019-05-13 10:34:32 +0530 |
commit | 87db1ca632bfbb66329c5729301d88ca30bed9b3 (patch) | |
tree | 130a90f28cbae927443c47efa096d792f9a06eff /libavfilter/vf_drawtext.c | |
parent | 98478c05edb674ec429c298fbe593bda493ba60f (diff) | |
download | ffmpeg-87db1ca632bfbb66329c5729301d88ca30bed9b3.tar.gz |
avfilter/drawtext: make command processing error-resilient
Prevents crash or interruption in text rendering
if new option string contains invalid values.
Diffstat (limited to 'libavfilter/vf_drawtext.c')
-rw-r--r-- | libavfilter/vf_drawtext.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index cca2cbcb88..b166574d71 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -862,20 +862,49 @@ static int config_input(AVFilterLink *inlink) static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags) { - DrawTextContext *s = ctx->priv; + DrawTextContext *old = ctx->priv; + DrawTextContext *new = NULL; + int ret; if (!strcmp(cmd, "reinit")) { - int ret; + new = av_mallocz(sizeof(DrawTextContext)); + if (!new) + return AVERROR(ENOMEM); + + new->class = &drawtext_class; + ret = av_opt_copy(new, old); + if (ret < 0) + goto fail; + + ctx->priv = new; + ret = av_set_options_string(ctx, arg, "=", ":"); + if (ret < 0) { + ctx->priv = old; + goto fail; + } + + ret = init(ctx); + if (ret < 0) { + uninit(ctx); + ctx->priv = old; + goto fail; + } + + new->reinit = 1; + + ctx->priv = old; uninit(ctx); - s->reinit = 1; - if ((ret = av_set_options_string(ctx, arg, "=", ":")) < 0) - return ret; - if ((ret = init(ctx)) < 0) - return ret; + av_freep(old); + + ctx->priv = new; return config_input(ctx->inputs[0]); - } + } else + return AVERROR(ENOSYS); - return AVERROR(ENOSYS); +fail: + av_log(ctx, AV_LOG_ERROR, "Failed to process command. Continuing with existing parameters.\n"); + av_freep(new); + return ret; } static int func_pict_type(AVFilterContext *ctx, AVBPrint *bp, |