Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100204 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30872 invoked from network); 13 Aug 2017 18:34:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Aug 2017 18:34:19 -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.94 as permitted sender) X-PHP-List-Original-Sender: newaltgroup@bk.ru X-Host-Fingerprint: 94.100.177.94 smtp34.i.mail.ru Received: from [94.100.177.94] ([94.100.177.94:57352] helo=smtp34.i.mail.ru) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/B1-34801-9AB90995 for ; Sun, 13 Aug 2017 14:34:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=bk.ru; s=mail; h=Mime-Version:Content-Transfer-Encoding:To:Date:Message-Id:In-Reply-To:Content-Type:From:References:Subject; bh=9fgMLACkdPbbPM17thS1I8XVH5LMvq9UXCvgSKjx9PQ=; b=gKd+HR2rKMic4FvOHlY4DbiT6aRxYCTj4zoJxGmZhnCfbAyUteE5PoQcS+hFZTO5HpqjneZFPxvJDJvBX0/2915rGgbF0XWpDa4BloPxM3PFdddHrJMiiQxvndihyNttYrRlEmJjqxh0w3rxfZF3QLg5WTU9Huh/dZpimY1N1aY=; Received: by smtp34.i.mail.ru with esmtpa (envelope-from ) id 1dgxiI-000692-Tl for internals@lists.php.net; Sun, 13 Aug 2017 21:34:15 +0300 References: Content-Type: multipart/alternative; boundary=Apple-Mail-9D079062-4E7A-46E6-9A88-93A7255DAB81 X-Mailer: iPhone Mail (14F89) In-Reply-To: Message-ID: <719FA910-0FB2-4D2E-A836-7FE485F3B159@bk.ru> Date: Sun, 13 Aug 2017 21:34:13 +0300 To: internals@lists.php.net Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (1.0) Authentication-Results: smtp34.i.mail.ru; auth=pass smtp.auth=newaltgroup@bk.ru smtp.mailfrom=newaltgroup@bk.ru X-7FA49CB5: 0D63561A33F958A56036AB604E04E4C661EFDCEF7633CA64BEB4949A5260A2F1725E5C173C3A84C3C8F21CEC4765490D7C1C88F97152F643D246AA24B5346CFAC4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F05F538519369F3743B503F486389A921A5CC5B56E945C8DA X-Mailru-Sender: 0119ABEC020BE1D27073DA0279C4911C5F1242A8B5FFA1524818F1D65DA28791E7F2A85972BD407842DB0A683240DB7ADF29DA55C944B5EC2CE1763A27C239DACC5971CC4652A97D0D4ABDE8C577C2ED X-Mras: OK Subject: Re: [Request][Discussion] Double value as array key improvement From: newaltgroup@bk.ru (Andrew Nester) --Apple-Mail-9D079062-4E7A-46E6-9A88-93A7255DAB81 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 Bumping the discussion because not everyone could see my previous email due t= o wrong configuration on my side, sorry. Cheers, Andrew= --Apple-Mail-9D079062-4E7A-46E6-9A88-93A7255DAB81--