From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-1399237-garchives=archives.gentoo.org@lists.gentoo.org> Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3CA37158090 for <garchives@archives.gentoo.org>; Sat, 21 May 2022 10:12:06 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5E97BE081B; Sat, 21 May 2022 10:12:05 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3D4CAE081B for <gentoo-commits@lists.gentoo.org>; Sat, 21 May 2022 10:12:05 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5B4583412DC for <gentoo-commits@lists.gentoo.org>; Sat, 21 May 2022 10:12:04 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id AC7F63AA for <gentoo-commits@lists.gentoo.org>; Sat, 21 May 2022 10:12:02 +0000 (UTC) From: "Michał Górny" <mgorny@gentoo.org> To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" <mgorny@gentoo.org> Message-ID: <1653127910.1f33f97b9e9c132d77d586d10bfe6ba0d3123050.mgorny@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/util/whirlpool.py X-VCS-Directories: lib/portage/util/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 1f33f97b9e9c132d77d586d10bfe6ba0d3123050 X-VCS-Branch: master Date: Sat, 21 May 2022 10:12:02 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 48444544-e0e1-41d7-9cb5-6f0ad1bf34f9 X-Archives-Hash: 9ca69252d2c216facd5c255ccb9c1acb commit: 1f33f97b9e9c132d77d586d10bfe6ba0d3123050 Author: Thomas Bracht Laumann Jespersen <t <AT> laumann <DOT> xyz> AuthorDate: Thu May 19 09:50:05 2022 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Sat May 21 10:11:50 2022 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1f33f97b lib/portage/util: fix bundled whirlpool on empty bytestring input The WhirlpoolAdd function did not consider zero-length input, so calls to update(b'') would produce out-of-bounds errors. This was not covered by any tests, because the constructor implicitly skipped the call to update on zero-length input. Add check for zero-length input to WhirlpoolAdd, and have the Whirlpool constructor skip calling update() only if arg is None. Closes: https://bugs.gentoo.org/846389 Signed-off-by: Thomas Bracht Laumann Jespersen <t <AT> laumann.xyz> Closes: https://github.com/gentoo/portage/pull/832 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> lib/portage/util/whirlpool.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/portage/util/whirlpool.py b/lib/portage/util/whirlpool.py index de344d8eb..9178d70c7 100644 --- a/lib/portage/util/whirlpool.py +++ b/lib/portage/util/whirlpool.py @@ -37,11 +37,9 @@ class Whirlpool: may be provided; if present, this string will be automatically hashed.""" - def __init__(self, arg=None): + def __init__(self, arg=b""): self.ctx = WhirlpoolStruct() - if arg: - self.update(arg) - self.digest_status = 0 + self.update(arg) def update(self, arg): """update(arg)""" @@ -71,7 +69,7 @@ class Whirlpool: return copy.deepcopy(self) -def new(init=None): +def new(init=b""): """Return a new Whirlpool object. An optional string argument may be provided; if present, this string will be automatically hashed.""" @@ -2183,6 +2181,8 @@ def WhirlpoolInit(ctx): def WhirlpoolAdd(source, sourceBits, ctx): if not isinstance(source, bytes): raise TypeError("Expected %s, got %s" % (bytes, type(source))) + if sourceBits == 0: + return carry = 0 value = sourceBits @@ -2350,3 +2350,9 @@ if __name__ == "__main__": Whirlpool(b"").hexdigest() == "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3" ) + w = Whirlpool() + w.update(b"") + assert ( + w.hexdigest() + == "19fa61d75522a4669b44e39c1d2e1726c530232130d407f89afee0964997f7a73e83be698b288febcf88e3e03c4f0757ea8964e59b63d93708b138cc42a66eb3" + )