From: Michael Niedermayer <[email protected]>

The previous code dependent on the input buffer matching the
buffer that has been provided by yadifs get_buffer.
The API does in now way gurantee this though its often true.
This fixes some out of array reads.
The regression test checksums change due to "out of picture" values
being initialized differently.
There should be no visual difference in the filters output

Signed-off-by: Michael Niedermayer <[email protected]>
---
 libavfilter/vf_yadif.c            |   28 ++++++++++++++++++++++-
 libavfilter/yadif.h               |    2 ++
 tests/ref/fate/filter-yadif-mode0 |   26 +++++++++++-----------
 tests/ref/fate/filter-yadif-mode1 |   44 ++++++++++++++++++-------------------
 4 files changed, 64 insertions(+), 36 deletions(-)

diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c
index a2b7337..b257166 100644
--- a/libavfilter/vf_yadif.c
+++ b/libavfilter/vf_yadif.c
@@ -113,6 +113,7 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef 
*dstpic,
         int w = dstpic->video->w;
         int h = dstpic->video->h;
         int refs = yadif->cur->linesize[i];
+        int absrefs = FFABS(refs);
         int df = (yadif->csp->comp[i].depth_minus1 + 8) / 8;
 
         if (i == 1 || i == 2) {
@@ -121,6 +122,12 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef 
*dstpic,
             h >>= yadif->csp->log2_chroma_h;
         }
 
+        if(yadif->temp_line_size < absrefs) {
+            av_free(yadif->temp_line);
+            yadif->temp_line = av_mallocz(2*64 + 5*absrefs);
+            yadif->temp_line_size = absrefs;
+        }
+
         for (y = 0; y < h; y++) {
             if ((y ^ parity) & 1) {
                 uint8_t *prev = &yadif->prev->data[i][y*refs];
@@ -128,7 +135,25 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef 
*dstpic,
                 uint8_t *next = &yadif->next->data[i][y*refs];
                 uint8_t *dst  = &dstpic->data[i][y*dstpic->linesize[i]];
                 int     mode  = y==1 || y+2==h ? 2 : yadif->mode;
-                yadif->filter_line(dst, prev, cur, next, w, y+1<h ? refs : 
-refs, y ? -refs : refs, parity ^ tff, mode);
+                int     prefs = y+1<h ? refs : -refs;
+                int     mrefs =     y ?-refs :  refs;
+
+                if(y<=1 || y+2>=h) {
+                    int j;
+                    uint8_t *tmp = yadif->temp_line + 64 + 2*absrefs;
+                    if(mode<2)
+                        memcpy(tmp+2*mrefs, cur+2*mrefs, w*df);
+                    memcpy(tmp+mrefs, cur+mrefs, w*df);
+                    memcpy(tmp      , cur      , w*df);
+                    if(prefs != mrefs) {
+                        memcpy(tmp+prefs, cur+prefs, w*df);
+                        if(mode<2)
+                            memcpy(tmp+2*prefs, cur+2*prefs, w*df);
+                    }
+                    cur = tmp;
+                }
+
+                yadif->filter_line(dst, prev, cur, next, w, prefs, mrefs, 
parity ^ tff, mode);
             } else {
                 memcpy(&dstpic->data[i][y*dstpic->linesize[i]],
                        &yadif->cur->data[i][y*refs], w*df);
@@ -342,6 +367,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     if (yadif->prev) avfilter_unref_bufferp(&yadif->prev);
     if (yadif->cur ) avfilter_unref_bufferp(&yadif->cur );
     if (yadif->next) avfilter_unref_bufferp(&yadif->next);
+    av_freep(&yadif->temp_line); yadif->temp_line_size = 0;
 }
 
 static int query_formats(AVFilterContext *ctx)
diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h
index 9d23870..ef6ce01 100644
--- a/libavfilter/yadif.h
+++ b/libavfilter/yadif.h
@@ -56,6 +56,8 @@ typedef struct {
 
     const AVPixFmtDescriptor *csp;
     int eof;
+    uint8_t *temp_line;
+    int temp_line_size;
 } YADIFContext;
 
 void ff_yadif_init_x86(YADIFContext *yadif);
diff --git a/tests/ref/fate/filter-yadif-mode0 
b/tests/ref/fate/filter-yadif-mode0
index e260977..d62ece7 100644
--- a/tests/ref/fate/filter-yadif-mode0
+++ b/tests/ref/fate/filter-yadif-mode0
@@ -2,31 +2,31 @@
 0,      64800,      64800,        0,   622080, 0x4440caef
 0,      72000,      72000,        0,   622080, 0xce67e69d
 0,      79200,      79200,        0,   622080, 0x1dbdc653
-0,      86400,      86400,        0,   622080, 0x82c591d1
+0,      86400,      86400,        0,   622080, 0x55c791d0
 0,      93600,      93600,        0,   622080, 0x8193740b
-0,     100800,     100800,        0,   622080, 0xcb219711
-0,     108000,     108000,        0,   622080, 0x1870783b
+0,     100800,     100800,        0,   622080, 0x7125970f
+0,     108000,     108000,        0,   622080, 0xeb63783a
 0,     115200,     115200,        0,   622080, 0x7080590b
-0,     122400,     122400,        0,   622080, 0x6df4175d
-0,     129600,     129600,        0,   622080, 0x6b530e95
+0,     122400,     122400,        0,   622080, 0x13f8175b
+0,     129600,     129600,        0,   622080, 0x3e550e94
 0,     136800,     136800,        0,   622080, 0x7f9d66f7
-0,     144000,     144000,        0,   622080, 0x338cda81
-0,     151200,     151200,        0,   622080, 0xb13797f8
-0,     158400,     158400,        0,   622080, 0xb51e7ca4
+0,     144000,     144000,        0,   622080, 0x068eda80
+0,     151200,     151200,        0,   622080, 0x843997f7
+0,     158400,     158400,        0,   622080, 0x88207ca3
 0,     165600,     165600,        0,   622080, 0x353eed75
 0,     172800,     172800,        0,   622080, 0xf93e92b0
 0,     180000,     180000,        0,   622080, 0xd0811094
 0,     187200,     187200,        0,   622080, 0xb04a3141
 0,     194400,     194400,        0,   622080, 0x4ab84909
-0,     201600,     201600,        0,   622080, 0xa0fcb8fb
-0,     208800,     208800,        0,   622080, 0x9003aebb
+0,     201600,     201600,        0,   622080, 0x4700b8f9
+0,     208800,     208800,        0,   622080, 0x6305aeba
 0,     216000,     216000,        0,   622080, 0x153faa3e
 0,     223200,     223200,        0,   622080, 0xae724063
-0,     230400,     230400,        0,   622080, 0xeb4de77a
+0,     230400,     230400,        0,   622080, 0xbe4fe779
 0,     237600,     237600,        0,   622080, 0x209ed8c7
 0,     244800,     244800,        0,   622080, 0xe2bbac96
 0,     252000,     252000,        0,   622080, 0xe945441e
-0,     259200,     259200,        0,   622080, 0x8f8cbd5f
-0,     266400,     266400,        0,   622080, 0xbc3cf717
+0,     259200,     259200,        0,   622080, 0x3590bd5d
+0,     266400,     266400,        0,   622080, 0x8f3ef716
 0,     273600,     273600,        0,   622080, 0x0109f125
 0,     280800,     280800,        0,   622080, 0x230c373f
diff --git a/tests/ref/fate/filter-yadif-mode1 
b/tests/ref/fate/filter-yadif-mode1
index b498137..2324266 100644
--- a/tests/ref/fate/filter-yadif-mode1
+++ b/tests/ref/fate/filter-yadif-mode1
@@ -5,27 +5,27 @@
 0,      75600,      75600,        0,   622080, 0x9a57891f
 0,      79200,      79200,        0,   622080, 0x1dbdc653
 0,      82800,      82800,        0,   622080, 0xc171c0c5
-0,      86400,      86400,        0,   622080, 0x82c591d1
+0,      86400,      86400,        0,   622080, 0x55c791d0
 0,      90000,      90000,        0,   622080, 0x20db9890
 0,      93600,      93600,        0,   622080, 0x8193740b
 0,      97200,      97200,        0,   622080, 0xdb181d52
-0,     100800,     100800,        0,   622080, 0xcb219711
+0,     100800,     100800,        0,   622080, 0x7125970f
 0,     104400,     104400,        0,   622080, 0xc2b913d1
-0,     108000,     108000,        0,   622080, 0x1870783b
+0,     108000,     108000,        0,   622080, 0xeb63783a
 0,     111600,     111600,        0,   622080, 0xf1d9c5fb
 0,     115200,     115200,        0,   622080, 0x7080590b
-0,     118800,     118800,        0,   622080, 0x669c5775
-0,     122400,     122400,        0,   622080, 0x6df4175d
+0,     118800,     118800,        0,   622080, 0xeda55774
+0,     122400,     122400,        0,   622080, 0x13f8175b
 0,     126000,     126000,        0,   622080, 0x01921a16
-0,     129600,     129600,        0,   622080, 0x6b530e95
+0,     129600,     129600,        0,   622080, 0x3e550e94
 0,     133200,     133200,        0,   622080, 0xd5047bc9
 0,     136800,     136800,        0,   622080, 0x7f9d66f7
-0,     140400,     140400,        0,   622080, 0xa8b006eb
-0,     144000,     144000,        0,   622080, 0x338cda81
+0,     140400,     140400,        0,   622080, 0x2fc806ea
+0,     144000,     144000,        0,   622080, 0x068eda80
 0,     147600,     147600,        0,   622080, 0xf0e125a7
-0,     151200,     151200,        0,   622080, 0xb13797f8
+0,     151200,     151200,        0,   622080, 0x843997f7
 0,     154800,     154800,        0,   622080, 0x4afe2976
-0,     158400,     158400,        0,   622080, 0xb51e7ca4
+0,     158400,     158400,        0,   622080, 0x88207ca3
 0,     162000,     162000,        0,   622080, 0x637fcbfe
 0,     165600,     165600,        0,   622080, 0x353eed75
 0,     169200,     169200,        0,   622080, 0xd9a8f5ac
@@ -34,30 +34,30 @@
 0,     180000,     180000,        0,   622080, 0xd0811094
 0,     183600,     183600,        0,   622080, 0x3039906f
 0,     187200,     187200,        0,   622080, 0xb04a3141
-0,     190800,     190800,        0,   622080, 0x52872cf9
+0,     190800,     190800,        0,   622080, 0xe62d2cfa
 0,     194400,     194400,        0,   622080, 0x4ab84909
 0,     198000,     198000,        0,   622080, 0x82de12ee
-0,     201600,     201600,        0,   622080, 0xa0fcb8fb
+0,     201600,     201600,        0,   622080, 0x4700b8f9
 0,     205200,     205200,        0,   622080, 0x7e849cc9
-0,     208800,     208800,        0,   622080, 0x9003aebb
-0,     212400,     212400,        0,   622080, 0xffe6f770
+0,     208800,     208800,        0,   622080, 0x6305aeba
+0,     212400,     212400,        0,   622080, 0x939bf771
 0,     216000,     216000,        0,   622080, 0x153faa3e
 0,     219600,     219600,        0,   622080, 0xb67f3233
 0,     223200,     223200,        0,   622080, 0xae724063
-0,     226800,     226800,        0,   622080, 0x15fe44b4
-0,     230400,     230400,        0,   622080, 0xeb4de77a
+0,     226800,     226800,        0,   622080, 0xed2b44b3
+0,     230400,     230400,        0,   622080, 0xbe4fe779
 0,     234000,     234000,        0,   622080, 0x380f8563
 0,     237600,     237600,        0,   622080, 0x209ed8c7
 0,     241200,     241200,        0,   622080, 0xb964d70f
 0,     244800,     244800,        0,   622080, 0xe2bbac96
 0,     248400,     248400,        0,   622080, 0x4f60f7f4
 0,     252000,     252000,        0,   622080, 0xe945441e
-0,     255600,     255600,        0,   622080, 0xd0afb742
-0,     259200,     259200,        0,   622080, 0x8f8cbd5f
+0,     255600,     255600,        0,   622080, 0xded0b740
+0,     259200,     259200,        0,   622080, 0x3590bd5d
 0,     262800,     262800,        0,   622080, 0xb9a15294
-0,     266400,     266400,        0,   622080, 0xbc3cf717
-0,     270000,     270000,        0,   622080, 0xb70b01a9
+0,     266400,     266400,        0,   622080, 0x8f3ef716
+0,     270000,     270000,        0,   622080, 0x3e2301a8
 0,     273600,     273600,        0,   622080, 0x0109f125
-0,     277200,     277200,        0,   622080, 0xcb3a371f
+0,     277200,     277200,        0,   622080, 0x5252371e
 0,     280800,     280800,        0,   622080, 0x230c373f
-0,     284400,     284400,        0,   622080, 0x82dfb1f2
+0,     284400,     284400,        0,   622080, 0x5a1ab1f1
-- 
1.7.9.5

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to