Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100248 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50873 invoked from network); 17 Aug 2017 17:01:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Aug 2017 17:01:42 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.46 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.214.46 mail-it0-f46.google.com Received: from [209.85.214.46] ([209.85.214.46:37644] helo=mail-it0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7F/80-34801-5FBC5995 for ; Thu, 17 Aug 2017 13:01:42 -0400 Received: by mail-it0-f46.google.com with SMTP id 76so4827718ith.0 for ; Thu, 17 Aug 2017 10:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3iji7+wtI3sJ5AQ2sYRbAngieUzgCdtr9KislCSp9Ds=; b=WgUjuDcWxLjWSE24XHXd/WHmJHC0+IDGrf0i5UzYDGdX+8R+dGt7K2aDWk4mx+kgDb 48UwrlWYlsq/eU3NSKze90nN+SkbWGqsXwhoR0+qHmEyyFpQ5RHwYIOjN2kZb7Ea90/n aDh0iSOXpTv9cA0i+Q08LCtqpsGDT8fRExxfDSNM87NugOW9hPcXJwPTC2Pdsg1CblqK RK+z++cfNKZ9pcRu4kXGuS9pQWUbUSbcLKr/6+8w/mvuf1aPQVJqJyqQv2TVXaPIWcZN 8MJaSZ7y/Mwoyc4qBdrw6QxbL9wfGqvGW+qwnyEMk5XfPHrpDvP+7Dw1Cb7wmSN0nZIr xjVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3iji7+wtI3sJ5AQ2sYRbAngieUzgCdtr9KislCSp9Ds=; b=qCrLEkqSEAPwnCQNgGFrPSRmITkPv4nyrQV1X/2NvOz9/kqFBXgvB+Q8Eav3JAhnWv tbEPg8bFpCSvcU7dG4SABR/4wia23UsMS0QdGlGFrYEm+9UAAaINgYI+V4Fyv2TFvQOJ DWEQO3EQTem6skwIASc+BIuJqBFUDW+E5tCttQ4zofdC1+X/fVCBdtH5m4XKshrolMFr fNQDyq1sFFlBzu0y5V+1H8YAXfLPeBGIXxR1YcqQdTqCqNOg50mvc/tfXcBruLFC8xoy LECDyZFclktl5JgAzPbVzNwpzSn4kBrkY07AfS8epxRVTHFv/mVl9WfBH8Fdoo+aBLUu ZUDA== X-Gm-Message-State: AHYfb5h/InIWb0kxFchIkLINDxiuCtvnXCL77tyPXgFC063uDciPT90v u4vJv1vBspLeBOJxqpjaLRTZ/yM1gw== X-Received: by 10.36.92.11 with SMTP id q11mr2548011itb.27.1502989298747; Thu, 17 Aug 2017 10:01:38 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.36.4 with HTTP; Thu, 17 Aug 2017 10:01:18 -0700 (PDT) In-Reply-To: <11BCF7F8-4AEE-43FE-9D26-7D64C54EA382@gmail.com> References: <11BCF7F8-4AEE-43FE-9D26-7D64C54EA382@gmail.com> Date: Thu, 17 Aug 2017 14:01:18 -0300 Message-ID: To: Andrew Nester Cc: PHP Internals Content-Type: multipart/alternative; boundary="001a11405a7c40cf7c0556f5f748" Subject: Re: [PHP-DEV] Re: [Request][Discussion] Double value as array key improvement From: david.proweb@gmail.com (David Rodrigues) --001a11405a7c40cf7c0556f5f748 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Just reposting to internals: David wrote: > If the key is user dependent (eg. Input from form), could it causes a warning too, right? I think that it should be considered a BC. Andrew Nester wrote: > Yes, warning will be emitted in this case as well but actual index will remain the same. > I could agree that it's minor BC break as it could affect users 2017-08-17 12:03 GMT-03:00 Andrew Nester : > > > > 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 in= t > 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#L1648) > >>> 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 previousl= y 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 solutio= n. > >>> 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 > > Hello internals! > > 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. > > Does it look like good idea? > > Thanks! --=20 David Rodrigues --001a11405a7c40cf7c0556f5f748--