[FFmpeg-devel] lavfi/deshake: Check alignment before calling asm init function

Submitted by Carl Eugen Hoyos on March 10, 2018, 7:50 p.m.

Details

Message ID CAB0OVGo=O4_fgmfwHb5gk06m6U470GMerXiQ4B4ko+2bbPqCcQ@mail.gmail.com
State Superseded
Headers show

Commit Message

Carl Eugen Hoyos March 10, 2018, 7:50 p.m.
Hi!

Attached patch fixes ticket #7078 for me.

Please comment, Carl Eugen

Comments

Carl Eugen Hoyos March 14, 2018, 12:15 a.m.
2018-03-10 20:50 GMT+01:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:
> Hi!
>
> Attached patch fixes ticket #7078 for me.

Ping.

Carl Eugen
Michael Niedermayer March 14, 2018, 10:50 p.m.
On Sat, Mar 10, 2018 at 08:50:08PM +0100, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch fixes ticket #7078 for me.
> 
> Please comment, Carl Eugen

>  vf_deshake.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 9f4517eae88416277aeb5bd5b677159914e9c451  0001-lavfi-deshake-Check-alignment-before-calling-asm-ini.patch
> From 75ead282c3aa3c214d37e766690e2edd037307c0 Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <cehoyos@ag.or.at>
> Date: Sat, 10 Mar 2018 20:46:21 +0100
> Subject: [PATCH] lavfi/deshake: Check alignment before calling asm init
>  function.
> 
> Do this for every frame to make sure dynamic filters do not
> cause crashes.
> 
> Fixes ticket #7078.
> ---
>  libavfilter/vf_deshake.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/libavfilter/vf_deshake.c b/libavfilter/vf_deshake.c
> index fb4eb35..75e9990 100644
> --- a/libavfilter/vf_deshake.c
> +++ b/libavfilter/vf_deshake.c
> @@ -342,10 +342,6 @@ static av_cold int init(AVFilterContext *ctx)
>  {
>      DeshakeContext *deshake = ctx->priv;
>  
> -    deshake->sad = av_pixelutils_get_sad_fn(4, 4, 1, deshake); // 16x16, 2nd source unaligned
> -    if (!deshake->sad)
> -        return AVERROR(EINVAL);
> -
>      deshake->refcount = 20; // XXX: add to options?
>      deshake->blocksize /= 2;
>      deshake->blocksize = av_clip(deshake->blocksize, 4, 128);
> @@ -432,6 +428,10 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>      }
>      av_frame_copy_props(out, in);
>  
> +    deshake->sad = av_pixelutils_get_sad_fn(4, 4, !((unsigned long)in->data[0] & 15), deshake); // 16x16, 2nd source unaligned
> +    if (!deshake->sad)
> +        return AVERROR(EINVAL);

does this need to check linesize too ?

no more comments from me

thx

[...]

Patch hide | download patch | download mbox

From 75ead282c3aa3c214d37e766690e2edd037307c0 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <cehoyos@ag.or.at>
Date: Sat, 10 Mar 2018 20:46:21 +0100
Subject: [PATCH] lavfi/deshake: Check alignment before calling asm init
 function.

Do this for every frame to make sure dynamic filters do not
cause crashes.

Fixes ticket #7078.
---
 libavfilter/vf_deshake.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vf_deshake.c b/libavfilter/vf_deshake.c
index fb4eb35..75e9990 100644
--- a/libavfilter/vf_deshake.c
+++ b/libavfilter/vf_deshake.c
@@ -342,10 +342,6 @@  static av_cold int init(AVFilterContext *ctx)
 {
     DeshakeContext *deshake = ctx->priv;
 
-    deshake->sad = av_pixelutils_get_sad_fn(4, 4, 1, deshake); // 16x16, 2nd source unaligned
-    if (!deshake->sad)
-        return AVERROR(EINVAL);
-
     deshake->refcount = 20; // XXX: add to options?
     deshake->blocksize /= 2;
     deshake->blocksize = av_clip(deshake->blocksize, 4, 128);
@@ -432,6 +428,10 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
     }
     av_frame_copy_props(out, in);
 
+    deshake->sad = av_pixelutils_get_sad_fn(4, 4, !((unsigned long)in->data[0] & 15), deshake); // 16x16, 2nd source unaligned
+    if (!deshake->sad)
+        return AVERROR(EINVAL);
+
     if (deshake->cx < 0 || deshake->cy < 0 || deshake->cw < 0 || deshake->ch < 0) {
         // Find the most likely global motion for the current frame
         find_motion(deshake, (deshake->ref == NULL) ? in->data[0] : deshake->ref->data[0], in->data[0], link->w, link->h, in->linesize[0], &t);
-- 
1.8.4.5