Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100182 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87881 invoked from network); 11 Aug 2017 12:53:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Aug 2017 12:53:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=newaltgroup@bk.ru; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=newaltgroup@bk.ru; sender-id=pass Received-SPF: pass (pb1.pair.com: domain bk.ru designates 94.100.177.111 as permitted sender) X-PHP-List-Original-Sender: newaltgroup@bk.ru X-Host-Fingerprint: 94.100.177.111 smtp51.i.mail.ru Received: from [94.100.177.111] ([94.100.177.111:35522] helo=smtp51.i.mail.ru) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A9/F5-34801-AB8AD895 for ; Fri, 11 Aug 2017 08:53:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=bk.ru; s=mail; h=Message-Id:In-Reply-To:To:References:Date:Subject:Mime-Version:Content-Type:From; bh=UG/zHlPPGH+JWK6hkW6b2vHzt5iCnTPHRGynsR4Dg9Y=; b=BHaxQapJPId+Rf9ewBI5iALLpaHAidJbAz5EiKnhS8U+dCuGKdO7xvSUOMFLncOAgVf4ef7J7IkA9ghCwUkk9GVubTek16NgQF+61eXegxrX6n5KxNRdizn0VWWnBm04cKwaZqEaixIl8b6HFwPlrutE7uaUSc/j0oXYeDSDDjU=; Received: by smtp51.i.mail.ru with esmtpa (envelope-from ) id 1dg9R8-0003cm-SY for internals@lists.php.net; Fri, 11 Aug 2017 15:53:11 +0300 Content-Type: multipart/alternative; boundary="Apple-Mail=_445FF9ED-B8EE-4785-A5DB-C7CA2CBC5EEF" Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Date: Fri, 11 Aug 2017 15:53:09 +0300 References: To: internals@lists.php.net In-Reply-To: Message-ID: X-Mailer: Apple Mail (2.3273) Authentication-Results: smtp51.i.mail.ru; auth=pass smtp.auth=newaltgroup@bk.ru smtp.mailfrom=newaltgroup@bk.ru X-7FA49CB5: 0D63561A33F958A53CE17B9C3DDD84A35C7943FA4F8C6DBF67734462BF2F38BC725E5C173C3A84C3AC6EB6EE67F779ACEB865B797B39E48B42F54486E6D6388DC4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F05F538519369F3743B503F486389A921A5CC5B56E945C8DA X-Mailru-Sender: 5359E0D685F10627A37960CE49917681EDACAF0E343504918F8EE97935EC2C274B9742EEAAA2AC3C18C1F6AB3FBD83F13DDE9B364B0DF289B1C9E140B68917A5027D9DD7AE851095AE208404248635DF X-Mras: OK Subject: Re: [Request][Discussion] Double value as array key improvement From: newaltgroup@bk.ru (Andrew Nester) --Apple-Mail=_445FF9ED-B8EE-4785-A5DB-C7CA2CBC5EEF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > 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=3D75053 = which resulted in following = pull request https://github.com/php/php-src/pull/2676 = >=20 > The problem here is following: when we=E2=80=99re using large numbers = as array index when adding new elements it could overwrite already = existing value. > Assume we have 2 indexes 5076964154930102272 and = 999999999999999999999999999999 with different value set for them. >=20 > Because 999999999999999999999999999999 is larger than maximum long int = number 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#L1= 648 = ) > But when double value is used as array indexes, it is converted to = long integer. (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=E2=80=99ve got index equal to = 5076964154930102272 and as a result - we=E2=80=99re overwriting = previously set value. >=20 > My suggestion is following: > 1) when double key is less than maximum possible long integer - = convert it to integer > 2) if it=E2=80=99s larger - convert it to string. >=20 > That=E2=80=99s what implemented in proposed PR. >=20 > Another possible option is just to throw warning in this case = (proposed by Nikita Popov) >=20 > I would happy to hear any feedback and suggestions about this = solution. > Thanks! Here is the alternative solution which emits E_WARNING in case of = integer array index overflow. https://github.com/php/php-src/pull/2677= --Apple-Mail=_445FF9ED-B8EE-4785-A5DB-C7CA2CBC5EEF--