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: 501814 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: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: 501813 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: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: 501812 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