Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61462 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30668 invoked from network); 19 Jul 2012 08:31:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jul 2012 08:31:04 -0000 Authentication-Results: pb1.pair.com header.from=ab@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=ab@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.73.107 as permitted sender) X-PHP-List-Original-Sender: ab@php.net X-Host-Fingerprint: 85.214.73.107 klapt.com Received: from [85.214.73.107] ([85.214.73.107:43680] helo=h1123647.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/C0-25752-7C5C7005 for ; Thu, 19 Jul 2012 04:31:03 -0400 Received: by h1123647.serverkompetenz.net (Postfix, from userid 1006) id 776339146AC; Thu, 19 Jul 2012 10:31:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on h1123647.serverkompetenz.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.5 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable version=3.3.1 Received: from webmail.klapt.com (h1123647.serverkompetenz.net [127.0.0.1]) by h1123647.serverkompetenz.net (Postfix) with ESMTP id 7B9CC9146A8; Thu, 19 Jul 2012 10:30:58 +0200 (CEST) Received: from 188.110.174.80 (SquirrelMail authenticated user anatoliy@belsky.info) by webmail.klapt.com with HTTP; Thu, 19 Jul 2012 10:30:58 +0200 Message-ID: Date: Thu, 19 Jul 2012 10:30:58 +0200 To: "Nikita Popov" Cc: "PHP internals" Reply-To: ab@php.net User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Subject: Re: [PHP-DEV] Integer overflows on float to int casts From: ab@php.net ("Anatoliy Belsky") Hi Nikita, that's exactly the subject I've tripped over trying to fix (apparently wrong) the issue #62477. The ticket is about LimitIterator accepting only long for start and offset, but being able to accept an Iterator from userland accepting floats for positions. For instance, the snippet like this looks also not very well $a = array(); $a[4000000000] = 42; print_r($a); Array ( [-294967296] => 42 ) So the mess is a bit bigger then and the way to solve this should include more consistent APIs as well, IMO. Again :). At the moment internal operations (like array having uint for positions) are a possible subset of userland. However internal APIs should be always the superset. Regards Anatoliy Am Do, 19.07.2012, 00:39 schrieb Nikita Popov: > Hi internals! > > When a large floating point number is cast to an integer we currently have very low-level C behavior (integer overflow and wraparound): > > $ /c/php-5.4.1/php -r 'var_dump((int) 4000000000);' > int(-294967296) > > $ /c/php-5.4.1/php -r 'var_dump((int) 6000000000);' > int(1705032704) > > As a fun fact, if you do the same thing with a string float the number if clipped instead of wrapped: > > $ /c/php-5.4.1/php -r 'var_dump((int) "4000000000");' > int(2147483647) > > This also applies to zend_parse_parameters. l arguments are wrapped, L arguments are clipped. > > In my eyes this kind of behavior has nothing to do in PHP. PHP is a high-level language, it shouldn't exhibit low-level stuff like integer overflows and wraparound. > > I think that at least for zend_parse_parameters this should be > changed. Overflowing float parameters should not be accepted. Instead throw the usual E_WARNING and return FAILURE. > > I'm not sure though what one should do about the explicit (int) cast. My preference would be to throw a notice and use the clipping > behavior. > > Thoughts? > > Nikita > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >