Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100278 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97391 invoked from network); 22 Aug 2017 08:49:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Aug 2017 08:49:04 -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.215.41 as permitted sender) X-PHP-List-Original-Sender: andrew.nester.dev@gmail.com X-Host-Fingerprint: 209.85.215.41 mail-lf0-f41.google.com Received: from [209.85.215.41] ([209.85.215.41:36958] helo=mail-lf0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/16-34801-FFFEB995 for ; Tue, 22 Aug 2017 04:49:04 -0400 Received: by mail-lf0-f41.google.com with SMTP id f7so56508584lfg.4 for ; Tue, 22 Aug 2017 01:49:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=rkbHystBATgJHDjmyPZjxvaayrNoAnq7Pdj3DFd4J+k=; b=VTyOYOGuNVNNyrw5J/Tk1PFAr4ymiFBehKdQ/Fto7iTSU2Hl0G0j3isPvtncpXO48d UN8P88FHxJ1fxB99rc09kTzMtteRddxY7pOd9gMPJHljeCG5ZxXfODx8KFLhT4BkDzDa gOVhbBdsp/i7WkWC8j2d77h0YgwB5Bqh8aQN03tpzeLGWH/uoawucdG8hadBDwc//NZY 4RDSUYA7UzynrDgvCfU55SI2IMBOwjxtoBxgLEHh9a79J6MeW9+8PYAWpyLd13lLcucr ar2tK8PErE87q/S3c8ISZW+D3pkePOFuFFkkenmzAJbpJiKbK0fm72NfpWwPH1ovZR0S y6Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=rkbHystBATgJHDjmyPZjxvaayrNoAnq7Pdj3DFd4J+k=; b=rkNgiOauM6AmVe4tGvEKkmLyMi3DcVt0ONmyrx1gGwV6rMcGcWwzARRS3crBMj84f4 DC8T26SZny0jxpZIbR9N3UlOMAAYIk3vW3wDeGRoi10tCGanesMs+Eb4PZFlI+gDhMbG X1pxKZ2aT/XX2Y1Qm7udGHjLlhVFk2Y7XiceXS0YjGGPI9zuwvHbWCedzZVv1wCkk4LX 5Zh9kmwtq3Ens8/dnfOKaPQAePdmO7eo6CHA3E7USr5jVmtXWiiqHmfviT4JxgP3GGJf 8oVVZ3YgKnbJMiiZepy1FNHHJKV50ehSUArCeWIfkUKEaVdURPEYU+n7vfeavPrgejP9 Qtqg== X-Gm-Message-State: AHYfb5iM5MPAexTXEFMSOUBL5LxNfzk/Eym6Ykr+yy6v8zjz7IXxsXi2 j0+BOQcnp1rbag== X-Received: by 10.46.84.85 with SMTP id y21mr7238209ljd.160.1503391740378; Tue, 22 Aug 2017 01:49:00 -0700 (PDT) Received: from [10.0.1.3] ([37.17.45.116]) by smtp.gmail.com with ESMTPSA id 3sm2644970ljv.70.2017.08.22.01.48.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Aug 2017 01:48:59 -0700 (PDT) Message-ID: <168FA3C9-672A-4BE4-BDA9-9314003EE13B@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_A717B149-0515-4E79-9549-7F7E00A236D5" Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Date: Tue, 22 Aug 2017 11:48:58 +0300 In-Reply-To: Cc: PHP internals To: Nikita Popov References: <11BCF7F8-4AEE-43FE-9D26-7D64C54EA382@gmail.com> X-Mailer: Apple Mail (2.3273) Subject: Re: [PHP-DEV] Re: [Request][Discussion] Double value as array key improvement From: andrew.nester.dev@gmail.com (Andrew Nester) --Apple-Mail=_A717B149-0515-4E79-9549-7F7E00A236D5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Aug 19, 2017, at 4:30 PM, Nikita Popov = wrote: >=20 > On Thu, Aug 17, 2017 at 5:03 PM, Andrew Nester = > = wrote: >=20 >=20 > > 13 =D0=B0=D0=B2=D0=B3. 2017 =D0=B3., =D0=B2 21:39, Andrew Nester = > = =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0): > > > > > > > >> 11 =D0=B0=D0=B2=D0=B3. 2017 =D0=B3., =D0=B2 15:53, Andrew Nester = > =D0=BD=D0=B0=D0=BF=D0=B8=D1= =81=D0=B0=D0=BB(=D0=B0): > >> > >> > >>> On Aug 11, 2017, at 2:10 PM, Andrew Nester > wrote: > >>> > >>> Hello everyone! > >>> > >>> 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 = > >>> > >>> 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. > >>> > >>> 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. > >>> > >>> 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. > >>> > >>> That=E2=80=99s what implemented in proposed PR. > >>> > >>> Another possible option is just to throw warning in this case = (proposed by Nikita Popov) > >>> > >>> 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 = > > > > My preferred solution is 2nd one (emitting warning) as it more = obvious for users, doesn't break previous behaviour. > > > > Cheers, > > Andrew >=20 > Hello internals! >=20 > I was working on solution for the problem of double to int conversion = for array indices and would like to create an RFC for proposed solution = - emitting warning when integer overflow happens during double to int = conversion. >=20 > Does it look like good idea? >=20 > Thanks! >=20 > Sounds good to me. Something you might want to consider is to also = throw a warning if the floating point number is not an exact integer. = For example allow a silent cast of 42.0 to 42, but throw a warning if = 42.5 is used as an index (or worse, 42.999999999, in which case it = likely isn't doing what the programmer thinks it's doing). >=20 > Nikita >=20 Hey Internals! I am planning to create RFC for this change but my account = (andrewnesterdev) doesn=E2=80=99t have enough permissions. Could please someone grant it that I could start creating it? Thanks!= --Apple-Mail=_A717B149-0515-4E79-9549-7F7E00A236D5--