Browse code

avfilter/delogo: Check that logo area is inside the picture

We can only remove the logo if it is inside the picture. We need at
least one pixel around the logo area for interpolation.

Fixes ticket #5527 (Delogo crash with x=0 and/or y=0).

Signed-off-by: Jean Delvare <jdelvare@suse.com>
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Jean Delvare authored on 2016/05/10 21:50:38
Showing 1 changed files
... ...
@@ -226,6 +226,20 @@ static av_cold int init(AVFilterContext *ctx)
226 226
     return 0;
227 227
 }
228 228
 
229
+static int config_input(AVFilterLink *inlink)
230
+{
231
+    DelogoContext *s = inlink->dst->priv;
232
+
233
+    /* Check whether the logo area fits in the frame */
234
+    if (s->x + (s->band - 1) < 0 || s->x + s->w - (s->band*2 - 2) > inlink->w ||
235
+        s->y + (s->band - 1) < 0 || s->y + s->h - (s->band*2 - 2) > inlink->h) {
236
+        av_log(s, AV_LOG_ERROR, "Logo area is outside of the frame.\n");
237
+        return AVERROR(EINVAL);
238
+    }
239
+
240
+    return 0;
241
+}
242
+
229 243
 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
230 244
 {
231 245
     DelogoContext *s = inlink->dst->priv;
... ...
@@ -284,6 +298,7 @@ static const AVFilterPad avfilter_vf_delogo_inputs[] = {
284 284
         .name         = "default",
285 285
         .type         = AVMEDIA_TYPE_VIDEO,
286 286
         .filter_frame = filter_frame,
287
+        .config_props = config_input,
287 288
     },
288 289
     { NULL }
289 290
 };