Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61449 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86006 invoked from network); 18 Jul 2012 23:22:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2012 23:22:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajfweb@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajfweb@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: ajfweb@googlemail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:45035] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/09-46800-53547005 for ; Wed, 18 Jul 2012 19:22:30 -0400 Received: by wibhn17 with SMTP id hn17so4422354wib.11 for ; Wed, 18 Jul 2012 16:22:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=b+90MnMyzf0N2BBfzHRZX2fkVHg9zti5asgffCjm4Ss=; b=kBZz4zhfO7dTY1tB8BGUjzMloZf6HTgx8tgjTHFVwWczP0dgU6cUjLFsZzSl7iBUOp BLzjE0xLgFzyJrw1hV17PKqgO9jFN7jNtcVvWt82Y/nTKtsnI5xfNuaTadzdlPxh/0IX 5CVV9dWAd4f4AXM8CvHV0aTEFSkaxmwkKZ7LbP4eI9my/hxg2sE7irEC+Zapot5dZuqd hpD6o+ErJsRWOCFPJ8nZvFnX74r/U22qmoGZopWT3Ft0zYC0vtgKwxrNwSAOdnzYa5cg AVKf5zOEEs7TTbXSWmkXtacCET7yuc4ptcRxeCzYeBp/QFSz2tdkAnRoshQ9f301h1V7 r/Wg== MIME-Version: 1.0 Received: by 10.216.92.133 with SMTP id j5mr640694wef.38.1342653746513; Wed, 18 Jul 2012 16:22:26 -0700 (PDT) Received: by 10.216.160.16 with HTTP; Wed, 18 Jul 2012 16:22:26 -0700 (PDT) Received: by 10.216.160.16 with HTTP; Wed, 18 Jul 2012 16:22:26 -0700 (PDT) In-Reply-To: References: Date: Thu, 19 Jul 2012 00:22:26 +0100 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary=e0cb4e6ffbf79e072804c522ef00 Subject: Re: [PHP-DEV] Integer overflows on float to int casts From: ajfweb@googlemail.com (Andrew Faulds) --e0cb4e6ffbf79e072804c522ef00 Content-Type: text/plain; charset=UTF-8 Cap it at INT_MAX, yeah, that seems reasonable. A notice seems reasonable but production servers displaying errors... devs will go mad :) On Jul 18, 2012 11:39 PM, "Nikita Popov" wrote: > 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 > > --e0cb4e6ffbf79e072804c522ef00--