aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-01-04 01:03:26 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-01-09 17:19:10 +0100
commit252ba4a9259fcaf18f5f340da364e7d536bc6788 (patch)
tree26abdfc3416f9018c4e8723aefb45f7e4b0ef091
parent5bb31e856d7c4f0aa3cefbe0d199be4f1cc0c4fb (diff)
downloadffmpeg-252ba4a9259fcaf18f5f340da364e7d536bc6788.tar.gz
avfilter/vf_sab: fix filtering tiny images
Fixes out of array reads Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 9bff052b51f27f6cce04e8d7d8b405c710d7ad67) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavfilter/vf_sab.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/libavfilter/vf_sab.c b/libavfilter/vf_sab.c
index aa38b533fe..b8af27cdcd 100644
--- a/libavfilter/vf_sab.c
+++ b/libavfilter/vf_sab.c
@@ -220,6 +220,19 @@ static int config_props(AVFilterLink *inlink)
#define NB_PLANES 4
+static inline int mirror(int x, int w)
+{
+ if (!w)
+ return 0;
+
+ while ((unsigned)x > (unsigned)w) {
+ x = -x;
+ if (x < 0)
+ x += 2 * w;
+ }
+ return x;
+}
+
static void blur(uint8_t *dst, const int dst_linesize,
const uint8_t *src, const int src_linesize,
const int w, const int h, FilterParam *fp)
@@ -253,8 +266,7 @@ static void blur(uint8_t *dst, const int dst_linesize,
for (dy = 0; dy < radius*2 + 1; dy++) {
int dx;
int iy = y+dy - radius;
- if (iy < 0) iy = -iy;
- else if (iy >= h) iy = h+h-iy-1;
+ iy = mirror(iy, h-1);
for (dx = 0; dx < radius*2 + 1; dx++) {
const int ix = x+dx - radius;
@@ -265,13 +277,11 @@ static void blur(uint8_t *dst, const int dst_linesize,
for (dy = 0; dy < radius*2+1; dy++) {
int dx;
int iy = y+dy - radius;
- if (iy < 0) iy = -iy;
- else if (iy >= h) iy = h+h-iy-1;
+ iy = mirror(iy, h-1);
for (dx = 0; dx < radius*2 + 1; dx++) {
int ix = x+dx - radius;
- if (ix < 0) ix = -ix;
- else if (ix >= w) ix = w+w-ix-1;
+ ix = mirror(ix, w-1);
UPDATE_FACTOR;
}
}