Commit e869d64580 for ffmpeg
commit e869d64580f2cfcef589a2f0c46b4339e30e1586
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Thu Nov 12 01:22:04 2026 +0100
avfilter/vf_convolution: set the filter function for identity matrices too
Fixes: NULL pointer dereference
Fixes: ORvkcJq0tqFe
Regression since: fe0fdc51b5
Found during the triage of a finding from the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25800
NULL pointer dereference Replicated through UnModified FFmpeg with ASAN
diff --git a/libavfilter/vf_convolution.c b/libavfilter/vf_convolution.c
index cc55beb0be..cf772af328 100644
--- a/libavfilter/vf_convolution.c
+++ b/libavfilter/vf_convolution.c
@@ -694,31 +694,18 @@ static int param_init(AVFilterContext *ctx)
s->size[i] = s->matrix_length[i];
} else if (s->matrix_length[i] == 9) {
s->size[i] = 3;
-
- if (!memcmp(matrix, same3x3, sizeof(same3x3))) {
- s->copy[i] = 1;
- } else {
- s->filter[i] = filter_3x3;
- s->copy[i] = 0;
- }
+ s->filter[i] = filter_3x3;
+ s->copy[i] = !memcmp(matrix, same3x3, sizeof(same3x3));
s->setup[i] = setup_3x3;
} else if (s->matrix_length[i] == 25) {
s->size[i] = 5;
- if (!memcmp(matrix, same5x5, sizeof(same5x5))) {
- s->copy[i] = 1;
- } else {
- s->filter[i] = filter_5x5;
- s->copy[i] = 0;
- }
+ s->filter[i] = filter_5x5;
+ s->copy[i] = !memcmp(matrix, same5x5, sizeof(same5x5));
s->setup[i] = setup_5x5;
} else if (s->matrix_length[i] == 49) {
s->size[i] = 7;
- if (!memcmp(matrix, same7x7, sizeof(same7x7))) {
- s->copy[i] = 1;
- } else {
- s->filter[i] = filter_7x7;
- s->copy[i] = 0;
- }
+ s->filter[i] = filter_7x7;
+ s->copy[i] = !memcmp(matrix, same7x7, sizeof(same7x7));
s->setup[i] = setup_7x7;
} else {
return AVERROR(EINVAL);
@@ -731,6 +718,19 @@ static int param_init(AVFilterContext *ctx)
if (s->copy[i] && (s->rdiv[i] != 1. || s->bias[i] != 0.))
s->copy[i] = 0;
+
+ if (s->depth > 8) {
+ if (s->mode[i] == MATRIX_ROW)
+ s->filter[i] = filter16_row;
+ else if (s->mode[i] == MATRIX_COLUMN)
+ s->filter[i] = filter16_column;
+ else if (s->size[i] == 3)
+ s->filter[i] = filter16_3x3;
+ else if (s->size[i] == 5)
+ s->filter[i] = filter16_5x5;
+ else if (s->size[i] == 7)
+ s->filter[i] = filter16_7x7;
+ }
}
} else if (!strcmp(ctx->filter->name, "prewitt")) {
for (i = 0; i < 4; i++) {
@@ -775,20 +775,6 @@ static int param_init(AVFilterContext *ctx)
}
if (!strcmp(ctx->filter->name, "convolution")) {
- if (s->depth > 8) {
- for (p = 0; p < s->nb_planes; p++) {
- if (s->mode[p] == MATRIX_ROW)
- s->filter[p] = filter16_row;
- else if (s->mode[p] == MATRIX_COLUMN)
- s->filter[p] = filter16_column;
- else if (s->size[p] == 3)
- s->filter[p] = filter16_3x3;
- else if (s->size[p] == 5)
- s->filter[p] = filter16_5x5;
- else if (s->size[p] == 7)
- s->filter[p] = filter16_7x7;
- }
- }
#if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64 && HAVE_X86ASM
ff_convolution_init_x86(s);
#endif