Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100246 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43514 invoked from network); 17 Aug 2017 15:03:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Aug 2017 15:03:53 -0000 Authentication-Results: pb1.pair.com header.from=andrew.nester.dev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=andrew.nester.dev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.181 as permitted sender) X-PHP-List-Original-Sender: andrew.nester.dev@gmail.com X-Host-Fingerprint: 209.85.128.181 mail-wr0-f181.google.com Received: from [209.85.128.181] ([209.85.128.181:32813] helo=mail-wr0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/AF-34801-950B5995 for ; Thu, 17 Aug 2017 11:03:53 -0400 Received: by mail-wr0-f181.google.com with SMTP id b65so46364231wrd.0 for ; Thu, 17 Aug 2017 08:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:references:from:in-reply-to:message-id:date:to :content-transfer-encoding:mime-version; bh=/7oVavjTEq6k9sCqVSZwePv4XDLRpEZJlMN7VoD8MqI=; b=Gs3CrL2IRUzHknNDMyGKsq85gsb4KPgpCLSxyzZyae0y2y+KRJRcnvoH/QeBr9dq8C Qn28sQif3w+iINSTMguY0unTELa8D6B7eYiwVY61Hnw3J4KUava5Hs3NUGZewh1Pe5gj zCb2CZwTIP7m2BgXOS28l9XADgfko0ST071tc3BbjJmZmFk0VfVVRUHVHUg2JlmBPUx4 BO5EvCu6iiTCSDYvfVZIXN7TSS5i0fbRWp8XMqiTND9IV0rsxZ680eCFCUzBssqipByd duTewCdVvYWXUa2ymLv9dui5cve+bSgMYtC/gj3SJjNMGSKvVtTLmDBZ0Xdc7EqE8AAo 5Ijg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:references:from:in-reply-to:message-id :date:to:content-transfer-encoding:mime-version; bh=/7oVavjTEq6k9sCqVSZwePv4XDLRpEZJlMN7VoD8MqI=; b=rtBkn157/yRZx20zN5ih7ugOyUVfldqjGp94myb0nt9WniFXZog3irwmApn00HFtow 3H0yHfxDplmUY0ovLFKgNFmKxh38R/ha0htlPGR5qdESRdaw5Qq7Y1XQxyIWqGNs8gEV P3Gf+52uvlvOvyDZHEy6O8eYiQRuaFHZo2uZCMjLsQQfmemwp2HtRkMf916zhORv5xH+ Qz9509MgrJ4mZOFSNEGftMAS+wkj8zP3CSBlv2tzYOrRpm9fosKUTnbE1xNCsckCK50K T3BZP5melkoM0qTLd+Fq7+GtNhcftGExCpxdIqc3VI8SoEQwK3JxnLZhRLnaDB5JhSdL E7qQ== X-Gm-Message-State: AHYfb5grLc673xLd8ER7MUBzSdQFLffY1je2+KextVcwr1dnskjwhy/5 xGVFD3yzZ6XiZpQ+qK8= X-Received: by 10.223.136.198 with SMTP id g6mr3865341wrg.280.1502982228388; Thu, 17 Aug 2017 08:03:48 -0700 (PDT) Received: from [10.78.196.72] ([46.56.173.64]) by smtp.gmail.com with ESMTPSA id a1sm4969118wra.17.2017.08.17.08.03.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Aug 2017 08:03:46 -0700 (PDT) References: Content-Type: multipart/alternative; boundary=Apple-Mail-A5565B19-E64D-4CF1-B0BC-BFB810B1C361 X-Mailer: iPhone Mail (14F89) In-Reply-To: Message-ID: <11BCF7F8-4AEE-43FE-9D26-7D64C54EA382@gmail.com> Date: Thu, 17 Aug 2017 18:03:27 +0300 To: internals@lists.php.net Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (1.0) Subject: Re: [Request][Discussion] Double value as array key improvement From: andrew.nester.dev@gmail.com (Andrew Nester) --Apple-Mail-A5565B19-E64D-4CF1-B0BC-BFB810B1C361 Content-Type: text/plain; charset=windows-1251 Content-Transfer-Encoding: quoted-printable > 13 =E0=E2=E3. 2017 =E3., =E2 21:39, Andrew Nester =ED=E0=EF=E8=F1=E0=EB(=E0): >=20 >=20 >=20 >> 11 =E0=E2=E3. 2017 =E3., =E2 15:53, Andrew Nester =ED= =E0=EF=E8=F1=E0=EB(=E0): >>=20 >>=20 >>> On Aug 11, 2017, at 2:10 PM, Andrew Nester wrote: >>>=20 >>> Hello everyone! >>>=20 >>> I was working on following request https://bugs.php.net/bug.php?id=3D750= 53 which resulted in following pull request https://github.com/php/php-src/p= ull/2676 >>>=20 >>> The problem here is following: when we=92re using large numbers as array= index when adding new elements it could overwrite already existing value. >>> Assume we have 2 indexes 5076964154930102272 and 99999999999999999999999= 9999999 with different value set for them. >>>=20 >>> Because 999999999999999999999999999999 is larger than maximum long int n= umber for 64-bit systems, it will be converted to double. (corresponding cod= e here https://github.com/php/php-src/blob/master/Zend/zend_language_scanner= .l#L1648) >>> But when double value is used as array indexes, it is converted to long i= nteger. (f.e., code is here https://github.com/php/php-src/blob/master/Zend/= zend_execute.c#L1573) >>> At this case it causes overflow and we=92ve got index equal to 507696415= 4930102272 and as a result - we=92re overwriting previously set value. >>>=20 >>> My suggestion is following: >>> 1) when double key is less than maximum possible long integer - convert i= t to integer >>> 2) if it=92s larger - convert it to string. >>>=20 >>> That=92s what implemented in proposed PR. >>>=20 >>> Another possible option is just to throw warning in this case (proposed b= y Nikita Popov) >>>=20 >>> I would happy to hear any feedback and suggestions about this solution. >>> Thanks! >>=20 >> Here is the alternative solution which emits E_WARNING in case of integer= array index overflow. >> https://github.com/php/php-src/pull/2677 >=20 > My preferred solution is 2nd one (emitting warning) as it more obvious for= users, doesn't break previous behaviour. >=20 > Cheers, > Andrew Hello internals! I was working on solution for the problem of double to int conversion for ar= ray indices and would like to create an RFC for proposed solution - emitting= warning when integer overflow happens during double to int conversion. Does it look like good idea? Thanks!= --Apple-Mail-A5565B19-E64D-4CF1-B0BC-BFB810B1C361--