Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100205 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38527 invoked from network); 13 Aug 2017 18:54:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Aug 2017 18:54:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=andrew.nester.dev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=andrew.nester.dev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.49 as permitted sender) X-PHP-List-Original-Sender: andrew.nester.dev@gmail.com X-Host-Fingerprint: 209.85.215.49 mail-lf0-f49.google.com Received: from [209.85.215.49] ([209.85.215.49:35506] helo=mail-lf0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 64/32-34801-3DC90995 for ; Sun, 13 Aug 2017 14:39:15 -0400 Received: by mail-lf0-f49.google.com with SMTP id t128so32433285lff.2 for ; Sun, 13 Aug 2017 11:39:15 -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=CvW8XPac0I0mxO1OGleFqkUetwtB9JTOpg3Arb1Q5Zc=; b=sOWP1g7dX3YXOP3BU4RcbbHpAIUeg/92wF5gAa7fqPP2vaE+lkENm/DECSvxx4m8+8 WZj7j2hi7EtUyAiBaJa+rmMhQsNyDkIa6gMVFCjX6jyaY0MhVA6DSThR+ZaOSQh7ujfx a5NETu+tVG2pF74D6+nH19XplM8rgwsAlakaFGH3hgGWKTKH9brHGeVpaSt4NGoD8irY iwX6R+gVYbYjwPWWuWWTb0R7OVkVD5nftGsvRilaPNHh8L1B1/gEfkqemD1KxWwSAxBm PTp3y1Gv4Uav6LZ5f6ogswprjMEcOTfn9BDlRdeAHzzdYNwyZbIrEmmnACUo69lZDZjM mxDg== 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=CvW8XPac0I0mxO1OGleFqkUetwtB9JTOpg3Arb1Q5Zc=; b=aSsHymAPYDpnEJNL/xnKWatFWSUsVGwEPZG3CH5BfOyV8Z58M8wMxQbHPtLnUA3zPp Ri+jsUz7RasVwIrKdIx0KhZXDjT7H2OiMCYYs3IYbzfZuHXzW+0ZwsAyhJZq/f/ywYHT EW8E8ei8L7y65Np6DGQg/f86d3wTa0gfT+ilY4CfZJUk4VCt+uLRCu3YLip8KNLZP9W8 H0MxsW6UhBRkvtq0m2ZyyO9s7lZzQi01VOqYdK+DFCFvM5ETxKEXyUyHDhSUJ+6hdiAK G+Vpd8rY/vy/4D9YMEN5GQvrKLLrjPgRW7eUN2bpsaRMpFazW8KE8JOV044h88RhPuNp Vjkw== X-Gm-Message-State: AHYfb5jBHycK/N6NGKsot9hRjNAZ2Fm0HwmBWdGzyrQ8WfrzWwQClh9Z slXbtNuQe0qBOcEfayw= X-Received: by 10.46.7.2 with SMTP id 2mr7212113ljh.59.1502649552111; Sun, 13 Aug 2017 11:39:12 -0700 (PDT) Received: from [192.168.100.4] ([178.121.236.178]) by smtp.gmail.com with ESMTPSA id s7sm1133421lfg.25.2017.08.13.11.39.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Aug 2017 11:39:10 -0700 (PDT) References: Content-Type: multipart/alternative; boundary=Apple-Mail-79E9542C-A334-469C-B5D9-7DB84F2E9532 X-Mailer: iPhone Mail (14F89) In-Reply-To: Message-ID: Date: Sun, 13 Aug 2017 21:39:09 +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-79E9542C-A334-469C-B5D9-7DB84F2E9532 Content-Type: text/plain; charset=windows-1251 Content-Transfer-Encoding: quoted-printable > 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=3D7505= 3 which resulted in following pull request https://github.com/php/php-src/pu= ll/2676 >>=20 >> The problem here is following: when we=92re using large numbers as array i= ndex when adding new elements it could overwrite already existing value. >> Assume we have 2 indexes 5076964154930102272 and 999999999999999999999999= 999999 with different value set for them. >>=20 >> Because 999999999999999999999999999999 is larger than maximum long int nu= mber for 64-bit systems, it will be converted to double. (corresponding code= 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 5076964154= 930102272 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 a= rray index overflow. > https://github.com/php/php-src/pull/2677 My preferred solution is 2nd one (emitting warning) as it more obvious for u= sers, doesn't break previous behaviour. Cheers, Andrew= --Apple-Mail-79E9542C-A334-469C-B5D9-7DB84F2E9532--