From patchwork Tue Sep 8 21:18:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22182 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3A1CD44BD83 for ; Wed, 9 Sep 2020 00:19:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1774268B71E; Wed, 9 Sep 2020 00:19:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5974A68B6C0 for ; Wed, 9 Sep 2020 00:19:24 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id e16so702867wrm.2 for ; Tue, 08 Sep 2020 14:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OQVGeVwEZTDw3ccFW0oEJqes9ad1nt4piK6R42rDwK0=; b=Sk2Ugcr2yy7HkMOo/5MKck1tX1+aRNuDL0cczNAKojhB2nsTgAqz5/G7rghOJqYMEh 3RXCV++xT9GzoNQeOI3kJyTN/pkpHSVHo+RNaBS9XYNzAYVzh1rA67acRBDCaeNpe81C onvpV7IxfpCS4uB+9bdDiHa+PFoYbDRaGyDnVyN4OzoQh/MXdcb13kUW5lK3vZsIDPE/ 3IpmTEtRWW40JDktCFAsnhuDwSa4wi99Gue0d0Lco3QVqG9t0XvnIJjOOK6r5OyrvJkS Dgo0dm54NTw+ly9Q28Rtch4CDe4xWm1e6TxZXAIe0Mm0YGJfyI66wfOwkh96tb/iLIE1 68xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OQVGeVwEZTDw3ccFW0oEJqes9ad1nt4piK6R42rDwK0=; b=smtRqQZ0BThohCri4h4ZMPE0oTAuyFMuVB8Nyt8lFyLJPWeKt4diickTPtkZYF45w8 F0K2BsWi1mLnKzW+ZG30IG0MaUNuOueNa3NtCa+cV5+Gr7Fwi2qZ2Wo6zgk1V71YOmz0 bSkasMI4ZSiZ2iRfOre0umykFXn9R+8bxaQmMayCWs7oqfW6p3G0Ea2upkxBfYrJ6apY SBrQhDEbhk92w+iRzUCMwexnldb+hyZS+2k+3iAHg6PQCqEZ27uBJbJ0ueMdNJliywCl 3V/Dn3os2SCNksOHGL1MNc2DGRuxx1TGn8j72TGj7wKJBIyRuIPqdt92kdJJMu08YacF RHig== X-Gm-Message-State: AOAM530KEgYPrJp7OGKvSlSSPNYLVsZZyoL3ivUEFsZc6KRALWkqGHB0 tw5yXeu0VQ+ukEHKDPBbKBIZaiCXbAM= X-Google-Smtp-Source: ABdhPJzOD6qqnCcBdwMVaRHXoC67T1UOEsRCjqILTjas8L9vdIVD+vO6vXuC9C+cevigu9njXpRaPw== X-Received: by 2002:adf:df87:: with SMTP id z7mr404921wrl.239.1599599963592; Tue, 08 Sep 2020 14:19:23 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id a15sm1074304wrn.3.2020.09.08.14.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 14:19:22 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Sep 2020 23:18:35 +0200 Message-Id: <20200908211856.16290-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200908211856.16290-1-andreas.rheinhardt@gmail.com> References: <20200908211856.16290-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/25] avfilter/af_headphone: Fix segfault when using very short streams X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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. Signed-off-by: Andreas Rheinhardt --- libavfilter/af_headphone.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index f488e0e28d..54b5dfec4c 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));