Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118333 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 17120 invoked from network); 31 Jul 2022 18:52:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Jul 2022 18:52:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B53641804D0 for ; Sun, 31 Jul 2022 13:52:17 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS398810 136.175.108.0/24 X-Spam-Virus: No X-Envelope-From: Received: from mail-108-mta111.mxroute.com (mail-108-mta111.mxroute.com [136.175.108.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 31 Jul 2022 13:52:17 -0700 (PDT) Received: from filter006.mxroute.com ([140.82.40.27] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta111.mxroute.com (ZoneMTA) with ESMTPSA id 1825607def00000261.002 for (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Sun, 31 Jul 2022 20:52:12 +0000 X-Zone-Loop: 8b6694dd323d5b6ec2750a43d0c2cead2b20ecce5302 X-Originating-IP: [140.82.40.27] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sandfox.me; s=x; h=MIME-Version:Content-Transfer-Encoding:Content-Type:References: In-Reply-To:Date:To:From:Subject:Message-ID:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Wg1QgoAf9TZ0k0A/GLqYTmLr2fDTqs1EeG+qhBAI5Ok=; b=MnXssUWhV7oKpc2/HLTCKITkGK JbX9gyJ0mgXnpgRgWDBXVd8pUu1tE2FilaoM2djicuBCdV9lKjKD3Av7rBa4AXxh85ZLFJD57HX+d RjyS3MRSxMwL3QvM6OoNk7zzK9PNcGRix8E1nRVcpb8X1ZfViXs7MfipSgSEJ4C4RrcG/XW06siYG HlMMr6xPR2h/nrfKQ0M6CSB3Sc27CI6agsqLiPaYZmKSgBmaDWHwRy6b3MN364gccpL+9Ts6UnhqJ xdterfhIeE1Pq+d4td7j+A3Q/35/Vn1JicI/AbEVsu0EzY9NFj3zcOanGpRNWkGjvHn3MqUhblRiJ Pccy1NDg==; Message-ID: <17f929199db20747cc977c3ce69acf4cbd12f6b4.camel@sandfox.me> To: Tim =?ISO-8859-1?Q?D=FCsterhus?= , PHP Internals List Date: Sun, 31 Jul 2022 23:52:08 +0300 In-Reply-To: References: <524dff3654286a804043c7c49dffe9c526d2114b.camel@sandfox.me> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.3 (3.44.3-1.fc36) MIME-Version: 1.0 X-AuthUser: sandfox@sandfox.me Subject: Re: [PHP-DEV] Negative values in PcgOneseq128XslRr64::jump($advance) From: sandfox@sandfox.me (Anton Smirnov) On Sun, 2022-07-31 at 19:52 +0200, Tim D=C3=BCsterhus wrote: > Hi >=20 > On 7/31/22 17:50, Anton Smirnov wrote: > > I'm writing a polyfill for ext-random and I noticed a small > > weirdness. > > PcgOneseq128XslRr64::jump() accepts negative $advance where it > > automagically becomes unsigned positive. >=20 > Yes, this is what happens when casting a negative signed integer to > an=20 > unsigned integer. It will wrap around to the maximum positive number=20 > minus whatever the negative value was. >=20 > > Does it make sense or maybe it's better to throw a ValueError > > there? >=20 > No it doesn't, especially since: >=20 > $a =3D $pcg->generate(); > $pcg->jump(-1); // jumps back 2^64 - 1 steps in a 64-bit system > var_dump($pcg->generate() =3D=3D=3D $a); // bool(false) >=20 > The PCG state is 128 Bits, so a negative jump does not work as > expected=20 > and thus should throw. >=20 > Would you mind filing an issue in the tracker, so that it can be=20 > properly referenced (and thus you properly credited for this find)? >=20 > https://github.com/php/php-src/issues >=20 > Best regards > Tim D=C3=BCsterhus Done,=20 The issue: https://github.com/php/php-src/issues/9212 Proposed patch: https://github.com/php/php-src/pull/9213