Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87894 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36652 invoked from network); 24 Aug 2015 14:15:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Aug 2015 14:15:17 -0000 Authentication-Results: pb1.pair.com header.from=anatol.php@belski.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=anatol.php@belski.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain belski.net from 85.214.73.107 cause and error) X-PHP-List-Original-Sender: anatol.php@belski.net X-Host-Fingerprint: 85.214.73.107 klapt.com Received: from [85.214.73.107] ([85.214.73.107:36218] helo=h1123647.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/04-32838-4F62BD55 for ; Mon, 24 Aug 2015 10:15:17 -0400 Received: by h1123647.serverkompetenz.net (Postfix, from userid 1006) id 6862723D615B; Mon, 24 Aug 2015 16:15:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on h1123647.serverkompetenz.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.5 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=unavailable version=3.3.2 Received: from w530phpdev (pD9FD2CBF.dip0.t-ipconnect.de [217.253.44.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h1123647.serverkompetenz.net (Postfix) with ESMTPSA id ED87F23D6003; Mon, 24 Aug 2015 16:15:11 +0200 (CEST) To: "'Rowan Collins'" , References: <02a601d0dbed$2c828df0$8587a9d0$@belski.net> <02ae01d0dbf5$01c17330$05445990$@belski.net> <02b001d0dbf5$607ab7b0$21702710$@belski.net> <02ba01d0dbfb$3de2c390$b9a84ab0$@belski.net> <55DA4924.2060401@gmail.com> In-Reply-To: <55DA4924.2060401@gmail.com> Date: Mon, 24 Aug 2015 16:15:09 +0200 Message-ID: <00c101d0de77$4a809680$df81c380$@belski.net> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQK9NdJN9egRUY1Umglkf8yuRLR3fgF0Y2w7Afrl8XkB4m4i6wDvLFLZAq3KEX4CFSYQhQFhBjf9m99XfjA= Content-Language: en-us Subject: RE: [PHP-DEV] Overflow checks and integral vars comparison From: anatol.php@belski.net ("Anatol Belski") Hi Rowan, > -----Original Message----- > From: Rowan Collins [mailto:rowan.collins@gmail.com] > Sent: Monday, August 24, 2015 12:29 AM > To: internals@lists.php.net > Subject: Re: [PHP-DEV] Overflow checks and integral vars comparison >=20 > On 22/08/2015 02:38, Sherif Ramadan wrote: > > I see. So you're not actually doing overflow checks then? Because at > > the point you'd be checking this zend_long or size_t it could have > > already overflowed or wrapped. The subject may have misled me to > > understand differently. >=20 > I think I understand the confusion: you are thinking of overflow as = something > which happens *within* a type based on some operation (addition, > multiplication, etc). >=20 > Anatol is talking about overflows which occur when casting *between* > types: a value of 2^33 can safely be passed around as a 64-bit = integer, no > overflow has occurred; but attempting to cast it to a 32-bit integer = will > immediately overflow the 32-bit integer. >=20 > Since many PHP extensions are wrappers around libraries which may only = deal in > 32-bit types, this cast is common, necessitating range checks like the = ones > proposed. >=20 Yep, that's the exact point. Not touching arithmetic operations as it is = a complex thing. Even on 64-bit fe there are intrinsics for doing = 128-bit math which could be used. ASM could be helpful ofc, however it = needs much care, fe even within GCC versions. So it is big and should be = another story :)=20 Overflows in the cast can happen when passing args, comparing variables = of different type or signess, or even with the numeric constants. Hence = that cast (zend_long)INT_MAX for example. At the end - it's still an = overflow/underflow issue. I'm going for an RFC with this to target 7.1. Thanks. anatol