avfilter/vf_convolution: Use avpriv_mirror

Fixes: out of array read
Fixes: #YWH-PGM40646-35

Found-by: jpraveenrao
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer
2026-03-06 03:21:37 +01:00
parent d707a4af80
commit 8970658472
2 changed files with 9 additions and 21 deletions
+3 -5
View File
@@ -21,6 +21,7 @@
#ifndef AVFILTER_CONVOLUTION_H
#define AVFILTER_CONVOLUTION_H
#include "avfilter.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
enum MatrixMode {
@@ -71,11 +72,8 @@ static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, int st
int i;
for (i = 0; i < 9; i++) {
int xoff = FFABS(x + ((i % 3) - 1));
int yoff = FFABS(y + (i / 3) - 1);
xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
int xoff = avpriv_mirror(x + (i % 3) - 1, w - 1);
int yoff = avpriv_mirror(y + (i / 3) - 1, h - 1);
c[i] = src + xoff * bpc + yoff * stride;
}
+6 -16
View File
@@ -520,11 +520,8 @@ static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, int st
int i;
for (i = 0; i < 25; i++) {
int xoff = FFABS(x + ((i % 5) - 2));
int yoff = FFABS(y + (i / 5) - 2);
xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
int xoff = avpriv_mirror(x + (i % 5) - 2, w - 1);
int yoff = avpriv_mirror(y + (i / 5) - 2, h - 1);
c[i] = src + xoff * bpc + yoff * stride;
}
@@ -536,11 +533,8 @@ static void setup_7x7(int radius, const uint8_t *c[], const uint8_t *src, int st
int i;
for (i = 0; i < 49; i++) {
int xoff = FFABS(x + ((i % 7) - 3));
int yoff = FFABS(y + (i / 7) - 3);
xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
int xoff = avpriv_mirror(x + (i % 7) - 3, w - 1);
int yoff = avpriv_mirror(y + (i / 7) - 3, h - 1);
c[i] = src + xoff * bpc + yoff * stride;
}
@@ -552,9 +546,7 @@ static void setup_row(int radius, const uint8_t *c[], const uint8_t *src, int st
int i;
for (i = 0; i < radius * 2 + 1; i++) {
int xoff = FFABS(x + i - radius);
xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
int xoff = avpriv_mirror(x + i - radius, w - 1);
c[i] = src + xoff * bpc + y * stride;
}
@@ -566,9 +558,7 @@ static void setup_column(int radius, const uint8_t *c[], const uint8_t *src, int
int i;
for (i = 0; i < radius * 2 + 1; i++) {
int xoff = FFABS(x + i - radius);
xoff = xoff >= h ? 2 * h - 1 - xoff : xoff;
int xoff = avpriv_mirror(x + i - radius, h - 1);
c[i] = src + y * bpc + xoff * stride;
}