summaryrefslogtreecommitdiff
path: root/libavfilter
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-08-28 10:56:20 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2021-02-27 07:21:00 +0100
commit9d82a7c813a14d741f4164b689111e80dde3bad6 (patch)
treeb179de622df5f491db8157ed4ec784898cdfe7cc /libavfilter
parent66e8328d049a60b1adb78f315ecd002f42954e1d (diff)
downloadffmpeg-9d82a7c813a14d741f4164b689111e80dde3bad6.tar.gz
avfilter/af_headphone: Fix segfault when using very short streams
When the headphone filter does its processing in the time domain, the lengths of the buffers involved are determined by three parameters, only two of which are relevant here: ir_len and air_len. The former is the length (in samples) of the longest HRIR input stream and the latter is the smallest power-of-two bigger than ir_len. Using optimized functions to calculate the convolution places restrictions on the alignment of the length of the vectors whose scalar product is calculated. Therefore said length, namely ir_len, is aligned on 32; but the number of elements of the buffers used is given by air_len and for ir_len < 16 a buffer overflow happens. This commit fixes this by ensuring that air_len is always >= 32 if processing happens in the time domain. Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> (cherry picked from commit 7b74e02ef2d0099a2e1f1d1cefc1fce2e041f618)
Diffstat (limited to 'libavfilter')
-rw-r--r--libavfilter/af_headphone.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index 3d4aca9fa8..ec5faf3da7 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -405,6 +405,9 @@ static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
int i, j, k;
s->air_len = 1 << (32 - ff_clz(ir_len));
+ if (s->type == TIME_DOMAIN) {
+ s->air_len = FFALIGN(s->air_len, 32);
+ }
s->buffer_length = 1 << (32 - ff_clz(s->air_len));
s->n_fft = n_fft = 1 << (32 - ff_clz(ir_len + s->size));