From patchwork Tue Aug 24 09:47:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 12454427 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86E32C4338F for ; Tue, 24 Aug 2021 09:49:36 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B0BC961374 for ; Tue, 24 Aug 2021 09:49:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B0BC961374 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 55707850; Tue, 24 Aug 2021 11:48:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 55707850 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1629798574; bh=9OEMyXBOqO5R68S0E43F1pysaOPhnHwrqN7vH6mFehw=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=eYJIirF20W6uJVdoTiQufOm+cqPVPMIRNEic48W8I+vGC4dPubO7Kb1STLAnchHNW CRImhgLIx4yzWJPTY/JFDmWzFEUBR1yWQUUjmQe7pXLKD2ZELfuN35cweNeNq5AH/t 2iBXiOhpG4FdsCkp7RtRDXzd67TFlowtVllM4cIs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 154C1F80431; Tue, 24 Aug 2021 11:48:08 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E7170F80171; Tue, 24 Aug 2021 11:48:06 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B758BF80171 for ; Tue, 24 Aug 2021 11:47:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B758BF80171 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="O/oA38N8"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="huG4p29E" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 6D78F21CFB for ; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cLEDrPrYMV/FRHUL7Wm4bivBZGnu+HKLLj0m8IHx+BI=; b=O/oA38N84wKvI5B13DuUNmDlL2NRI00O37Xv7f/CS6FGyV8XXTIQZcsOttltYUV0LRiXfq d42i2pcrtiBYL6jf2p92XnxA2ONzcxAHBKW8foBJC8n0N3+kb/1HVi9HpoTJA/Ngcgfekk q97eEc00Tqy2PFGPJ9EMCOn3AaHetNk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cLEDrPrYMV/FRHUL7Wm4bivBZGnu+HKLLj0m8IHx+BI=; b=huG4p29EUmxYVqqv2UHw86Va7Wtof0d1WpqyknSWB2yW2WPHWf1Tc7JqAvgayNxYA+tdcX VdFeFPBDNnsd8uDg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 5DD14A3BBA; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-utils 1/5] aplay: Fix conversion of unsigned samples in peak calculation Date: Tue, 24 Aug 2021 11:47:52 +0200 Message-Id: <20210824094756.12540-2-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210824094756.12540-1-tiwai@suse.de> References: <20210824094756.12540-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The XOR with the mask has to be applied before calculating abs value. Signed-off-by: Takashi Iwai --- aplay/aplay.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/aplay/aplay.c b/aplay/aplay.c index cc51dcb48bba..91af244edb60 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -1828,7 +1828,8 @@ static void compute_max_peak(u_char *data, size_t samples) sval = le16toh(*valp); else sval = be16toh(*valp); - sval = abs(sval) ^ mask; + sval ^= mask; + sval = abs(sval); if (max_peak[c] < sval) max_peak[c] = sval; valp++; @@ -1848,11 +1849,12 @@ static void compute_max_peak(u_char *data, size_t samples) } else { val = (valp[0]<<16) | (valp[1]<<8) | valp[2]; } + val ^= mask; /* Correct signed bit in 32-bit value */ if (val & (1<<(bits_per_sample-1))) { val |= 0xff<<24; /* Negate upper bits too */ } - val = abs(val) ^ mask; + val = abs(val); if (max_peak[c] < val) max_peak[c] = val; valp += 3; @@ -1871,7 +1873,8 @@ static void compute_max_peak(u_char *data, size_t samples) val = le32toh(*valp); else val = be32toh(*valp); - val = abs(val) ^ mask; + val ^= mask; + val = abs(val); if (max_peak[c] < val) max_peak[c] = val; valp++; From patchwork Tue Aug 24 09:47:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 12454429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C10A9C4338F for ; Tue, 24 Aug 2021 09:49:55 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 192B961374 for ; Tue, 24 Aug 2021 09:49:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 192B961374 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id A1B4B1660; Tue, 24 Aug 2021 11:49:03 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz A1B4B1660 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1629798593; bh=7VXPzWYnLHpltXU6CLV6TkVMUVgXzOw466WPIcw5pOA=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=MYSpGNo8u/6FMxHgO6xjKt8Zw1Bi7wkVGgXFOXGUyo/jtyNaH8JHG4EQ6rcsvn3Sw kQivMzkSCXIuTJ2e/8nzq5jJ7l6U0IqtmV2knNvD0nBM28kgmJDZvF5fKuhTZ4urde 4IeXOyLR43amrDbbeNl1Jz5+azC0S52Q30qFyBuc= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3D4D7F804E7; Tue, 24 Aug 2021 11:48:11 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7742DF804B4; Tue, 24 Aug 2021 11:48:08 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 8CCECF801D5 for ; Tue, 24 Aug 2021 11:47:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 8CCECF801D5 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="LFv5WK5Q"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="Ey2eComZ" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7B023220DF for ; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LDCWOOXzkS3uFLj0tdTBK+1YuvOwRHLtrbXTfXu/rMg=; b=LFv5WK5QJR6J9qiQvGbCWjYSNsMFEkMy43s5QX/tSn1D1w7t605ghKZMrrpNUk3gSezhJ6 O7E7oTvAvUB0ZiMkrHeT53KQ5kywKSse6XAdManv9Emod3mtHPcLZzbkHjrVxFPNCWdQAv 3rus8FZjekjgB39AGqoK38W8gLO5tmA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LDCWOOXzkS3uFLj0tdTBK+1YuvOwRHLtrbXTfXu/rMg=; b=Ey2eComZwIey6tFY94xL6eJWLlvvq6hqrHKMp8IdZXWBhCeSa59zAQZo5MZEVPztXxpqkQ 2yxtkffaNBnSdqBA== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 6B1B9A3B87; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-utils 2/5] aplay: Handle 16bit sample negative overflow in peak calculations Date: Tue, 24 Aug 2021 11:47:53 +0200 Message-Id: <20210824094756.12540-3-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210824094756.12540-1-tiwai@suse.de> References: <20210824094756.12540-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The handling of 16bit samples in the peak calculations has a bug when a sample with 0x8000 is passed. As abs() treats 32bit int, it returns 0x8000. And yet the code stores back into 16bit value again. To fix that overflow, use 32bit value (i.e. val instead of sval) for the further calculations. Signed-off-by: Takashi Iwai --- aplay/aplay.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aplay/aplay.c b/aplay/aplay.c index 91af244edb60..c884346c9f25 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -1829,9 +1829,9 @@ static void compute_max_peak(u_char *data, size_t samples) else sval = be16toh(*valp); sval ^= mask; - sval = abs(sval); - if (max_peak[c] < sval) - max_peak[c] = sval; + val = abs(sval); + if (max_peak[c] < val) + max_peak[c] = val; valp++; if (vumeter == VUMETER_STEREO) c = !c; From patchwork Tue Aug 24 09:47:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 12454431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E256C4338F for ; Tue, 24 Aug 2021 09:50:15 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C3FF3613AB for ; Tue, 24 Aug 2021 09:50:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C3FF3613AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id BC2CD1661; Tue, 24 Aug 2021 11:49:22 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz BC2CD1661 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1629798612; bh=4QGBDRNN91aBCaKqAb+M+sVOeGP8GEyGOkt/mSWw/QE=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ht4XwqBZwO5pFMg1bP8FoWG1H+fOK4J6IVVTbLCuWjHom/Rd+u3BjQvf940ckR2Mu zXmUyTsdeCAFHXIXWMntgG5vgacMEEvvysPnR3TPj49DQ/SjmSBQHtJc+MlidgYcZL UMSZNTSMIiU93dNkZo6q/bN8hm5EfaSjAMlPLxoE= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id F27C4F804F1; Tue, 24 Aug 2021 11:48:11 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 2DCDAF804D0; Tue, 24 Aug 2021 11:48:08 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id EC6AFF801D8 for ; Tue, 24 Aug 2021 11:47:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz EC6AFF801D8 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="R5DSvBxM"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="KZmzUslK" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8888120050 for ; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k40+ME2hFZhc/8Xrg/QR3oc+2hv7ZLPb9gVSAkpyVpo=; b=R5DSvBxM3m2Pv8YpUX68vO4dLAuVT9xPnawgxxN69nxxInAZl1DT1nDq3Z6Im4QNfhe0Xw hKDqaTS5EQ02B8eG3lEwZe154jHlMOdi8sXihU9gLHpWeasIgVkA7mBeBZazPdjIJe7VOT jpLyJXKj3CC5vepP6/PhChYJAhT4ACc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k40+ME2hFZhc/8Xrg/QR3oc+2hv7ZLPb9gVSAkpyVpo=; b=KZmzUslK4kmIvLhA+0q+OlUgkXI96iIaRoCAI8cDNUKyX/Y3ogunygXzjQzBqf8OR5UM+I 2P1YfYfHfWWM4dBQ== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 790B9A3BBA; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-utils 3/5] aplay: Don't pass most negative integer to abs() in peak calculations Date: Tue, 24 Aug 2021 11:47:54 +0200 Message-Id: <20210824094756.12540-4-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210824094756.12540-1-tiwai@suse.de> References: <20210824094756.12540-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The return value from abs() for the most negative integer is undefined. Cap it properly for the 32bit sample handling. Signed-off-by: Takashi Iwai --- aplay/aplay.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aplay/aplay.c b/aplay/aplay.c index c884346c9f25..2543de5b6cd8 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -1874,7 +1874,10 @@ static void compute_max_peak(u_char *data, size_t samples) else val = be32toh(*valp); val ^= mask; - val = abs(val); + if (val == 0x80000000U) + val = 0x7fffffff; + else + val = abs(val); if (max_peak[c] < val) max_peak[c] = val; valp++; From patchwork Tue Aug 24 09:47:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 12454433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E988C4338F for ; Tue, 24 Aug 2021 09:50:38 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A62A261374 for ; Tue, 24 Aug 2021 09:50:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A62A261374 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1A70D1655; Tue, 24 Aug 2021 11:49:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1A70D1655 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1629798636; bh=ge2O+WYs6o2RueQwM8MelClAGGp8etI/DwkI63k+lv4=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=L8PpT+9y6I8MxM9rClCxMU/n6J1UBHU6oNMqeWupkUnyJRNxLd3OAtE+CeJMrMPB2 IE8hM9rjAwqIK0V33fNhS4mYo/lUJRpkS5hhJowRu8BS5LX8xizSOCVHwUO9dftS45 Pjmf2uodhT7jPjtoVs1Qkwmf8slUoTPm8QRYf4Y0= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 976BAF804FA; Tue, 24 Aug 2021 11:48:14 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id B9857F804FB; Tue, 24 Aug 2021 11:48:12 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E0C7DF80224 for ; Tue, 24 Aug 2021 11:48:02 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E0C7DF80224 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="DHogabIo"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="9sQrggly" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 95AC5220E1 for ; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hXWJMeOYizQPoO0kl/uU+hPYHai/ibBD3dCVIkmG/QQ=; b=DHogabIokRmx2Oi5B8scHhBDOXZj+pqxks4auyHXvDSF9XJccseX6jeP5GPriYy1qyH75I mupoQ2RV1J7hGN1NagJvGy6ue0ljb141DdPHY7yBF9iwHb+SZzfa+EkPboUf2m0ZNCUewh Zuwhxr0YO4ZwSUnAHjRG14Qsw/l/VCg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hXWJMeOYizQPoO0kl/uU+hPYHai/ibBD3dCVIkmG/QQ=; b=9sQrgglyR6JF+7X7Hy/5eNrnOpF0SZsPJRpuFbcgRsCPkOif9/tHyRBYZtl2H7HTocL7Qp uLCb3TqWrLxzyoDQ== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 8695EA3B87; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-utils 4/5] aplay: Handle upper bound in peak calculations Date: Tue, 24 Aug 2021 11:47:55 +0200 Message-Id: <20210824094756.12540-5-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210824094756.12540-1-tiwai@suse.de> References: <20210824094756.12540-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Make sure that the calculated max_peak[] won't go beyond the sample max resolution. Signed-off-by: Takashi Iwai --- aplay/aplay.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aplay/aplay.c b/aplay/aplay.c index 2543de5b6cd8..a51a37ba34bd 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -1898,6 +1898,8 @@ static void compute_max_peak(u_char *data, size_t samples) max = 0x7fffffff; for (c = 0; c < ichans; c++) { + if (max_peak[c] > max) + max_peak[c] = max; if (bits_per_sample > 16) perc[c] = max_peak[c] / (max / 100); else From patchwork Tue Aug 24 09:47:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 12454435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4EF7C4338F for ; Tue, 24 Aug 2021 09:50:48 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F268161374 for ; Tue, 24 Aug 2021 09:50:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F268161374 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 8D1FE1674; Tue, 24 Aug 2021 11:49:56 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8D1FE1674 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1629798646; bh=9GwZ0mnoGOTlHyv2qonH8DOi2yUrWuKy441bw5OWFZM=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=WrXY6iX84Rqxe5xa50BaQi4uruRYJQBMSSM1zFq7t+7M8QLqqW33VlSE8ujgUchld a43ng8oskC2opxmDUiHdjK2G+am7TFiC5QK3WkPk6xWq+03vItVz7rrFqHYK07ScWc +do22e9NFgZLFb8FnINgYNS6fIYJNYYliU1BQg0I= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 7056EF804FD; Tue, 24 Aug 2021 11:48:16 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 13BDFF804FD; Tue, 24 Aug 2021 11:48:15 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E9DCAF80430 for ; Tue, 24 Aug 2021 11:48:03 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E9DCAF80430 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="v4Cd9m1u"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="E6aDgWOR" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id A3BB1220E6 for ; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+fg/W80wM02FV81zqY8zIqz3dFIExfCosUOIN3WBP4w=; b=v4Cd9m1uyljPnbBBvvP9bX7AaazBoRWqrhggILIRXZHrnSTAA1Lm6ewfuhxWgCpi++JSgx hyADhQNHz39NWiqNt6o51kURMrffzIWo9FyzatFq+TAw/AHV036FTcHQ5s2VzSdLZpmg+V iz3oSA7cWtFKnOEjFNPtdFKfsjYgX2s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629798477; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+fg/W80wM02FV81zqY8zIqz3dFIExfCosUOIN3WBP4w=; b=E6aDgWORjYgkVntZ/+NSqNN9NUjR7oxyoYAXpOQaMdO6HAnfHLLRgHOm0F8kb6JzeWzXk8 n56wfWuhz+IHGJBg== Received: from alsa1.nue.suse.com (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 94307A3BBA; Tue, 24 Aug 2021 09:47:57 +0000 (UTC) From: Takashi Iwai To: alsa-devel@alsa-project.org Subject: [PATCH alsa-utils 5/5] aplay: Fix out-of-bound access in stereo VU meter drawing Date: Tue, 24 Aug 2021 11:47:56 +0200 Message-Id: <20210824094756.12540-6-tiwai@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210824094756.12540-1-tiwai@suse.de> References: <20210824094756.12540-1-tiwai@suse.de> MIME-Version: 1.0 X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The left channel drawing of a stereo VU meter has a bug where it may access a negative array index. Signed-off-by: Takashi Iwai --- aplay/aplay.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/aplay/aplay.c b/aplay/aplay.c index a51a37ba34bd..63a4e3437fd9 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -1758,10 +1758,12 @@ static void print_vu_meter_stereo(int *perc, int *maxperc) if (c) memset(line + bar_length + 6 + 1, '#', p); else - memset(line + bar_length - p - 1, '#', p); - p = maxperc[c] * bar_length / 100; - if (p > bar_length) - p = bar_length; + memset(line + bar_length - p, '#', p); + p = maxperc[c] * bar_length / 100 - 1; + if (p < 0) + p = 0; + else if (p >= bar_length) + p = bar_length - 1; if (c) line[bar_length + 6 + 1 + p] = '+'; else