History

avfilter/avfiltergraph: Fix use-after-free when inserting auto-converter

When inserting an auto-resampler, it may be that the configuration of the filters that the auto-resampler is supposed to connect is already partially merged, i.e. converter->inputs[0].incfg.foo and converter->outputs[0].outcfg.foo (where foo is one of formats, samplerates, channel_layouts) can coincide. Therefore merging the converter filter's input link might modify the outcfg of the converter' outlink. Yet the current code in avfiltergraph.c used pointers from before merging the inlink for merging the outlink, leading to a use-after-free in command lines like: $ ffmpeg -f lavfi -i anullsrc=cl=stereo -lavfi channelsplit,axcorrelate -f null - Fix this by not using outdated values when merging the outlink. This is a regression since 85a6404d7e6c759ddf71d6374812d7ff719728ec.

Andreas Rheinhardt committed 5 years ago

Commit 5e1dac31 parent 4ff88401 file · +5 −6Browse files

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

Unified · Split

libavfilter/avfiltergraph.c+5−6
@@ -520,14 +520,13 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) · 519 unmodified lines
520520 av_assert0(outlink-> incfg.channel_layouts->refcount > 0);
521521 av_assert0(outlink->outcfg.channel_layouts->refcount > 0);
522522 }
523+#define MERGE(merger, link) \
524+ ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \
525+ FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg)))
523526 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
524527 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
525− void *ia = FF_FIELD_AT(void *, m->offset, inlink->incfg);
526− void *ib = FF_FIELD_AT(void *, m->offset, inlink->outcfg);
527− void *oa = FF_FIELD_AT(void *, m->offset, outlink->incfg);
528− void *ob = FF_FIELD_AT(void *, m->offset, outlink->outcfg);
529− if ((ret = m->merge(ia, ib)) <= 0 ||
530− (ret = m->merge(oa, ob)) <= 0) {
528+ if ((ret = MERGE(m, inlink)) <= 0 ||
529+ (ret = MERGE(m, outlink)) <= 0) {
531530 if (ret < 0)
532531 return ret;
533532 av_log(log_ctx, AV_LOG_ERROR,

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