Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87891 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32436 invoked from network); 24 Aug 2015 13:57:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Aug 2015 13:57:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=anatol.php@belski.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=anatol.php@belski.net; 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:34287] helo=h1123647.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/33-32838-0E22BD55 for ; Mon, 24 Aug 2015 09:57:52 -0400 Received: by h1123647.serverkompetenz.net (Postfix, from userid 1006) id B1D8E23D6299; Mon, 24 Aug 2015 15:57:48 +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 2DEB823D6003; Mon, 24 Aug 2015 15:57:46 +0200 (CEST) To: "'Jakub Zelenka'" Cc: "'Dmitry Stogov'" , "'Xinchen Hui'" , "'Nikita Popov'" , "'Pierre Joye'" , "'Bob Weinand'" , "'Matt Wilmas'" , "'PHP internals list'" References: <02a601d0dbed$2c828df0$8587a9d0$@belski.net> In-Reply-To: Date: Mon, 24 Aug 2015 15:57:41 +0200 Message-ID: <00ad01d0de74$db4773d0$91d65b70$@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: AQK9NdJN9egRUY1Umglkf8yuRLR3fgF4idffnDaM04A= Content-Language: en-us Subject: RE: [PHP-DEV] Re: Overflow checks and integral vars comparison From: anatol.php@belski.net ("Anatol Belski") Hi Jakub, > -----Original Message----- > From: jakub.php@gmail.com [mailto:jakub.php@gmail.com] On Behalf Of = Jakub > Zelenka > Sent: Sunday, August 23, 2015 8:29 PM > To: Anatol Belski > Cc: Dmitry Stogov ; Xinchen Hui ; > Nikita Popov ; Pierre Joye = ; > Bob Weinand ; Matt Wilmas > ; PHP internals list = > Subject: [PHP-DEV] Re: Overflow checks and integral vars comparison >=20 > Hi Anatol, >=20 > On Fri, Aug 21, 2015 at 9:41 AM, Anatol Belski > wrote: >=20 > > Hi, > > > > Resending this as missed internals at the start. > > > > I was lately rethinking some part of the 64-bit RFC, and also seeing > > now Jakub's work on catching overflows in ext/openssl and Matt > > Williams suggestions on it (which was going a bit more global over > > it). So I came up with these macros with two goals > > > > - standardize the overflow checks > > - do actualy checks only on architectures where it's needed > > - simplify the checks where external libs (openssl, libxml, etc.) = use > > firm datatypes like int > > > > #if SIZEOF_INT =3D=3D SIZEOF_ZEND_LONG > > # define ZEND_LONG_INT_OVFL(zl) (0) > > # define ZEND_LONG_INT_UDFL(zl) (0) > > #else > > # define ZEND_LONG_INT_OVFL(zlong) ((zlong) > (zend_long)INT_MAX) # > > define > > ZEND_LONG_INT_UDFL(zlong) ((zlong) < (zend_long)INT_MIN) #endif > > > > #define ZEND_SIZE_T_INT_OVFL(size) ((size) > (size_t)INT_MAX) > > > > So having it like > > > > If (ZEND_LONG_INT_OVFL(x)) { > > return; > > } > > > > > I think this makes and sense and it's a good start. >=20 > What I think would be even more useful is to have such checks in ZPP. = The thing > is that usual use case for libs where the most used integer type is = int (e.g. > openssl) is following: >=20 > 1. Get zend_long "l" resp. string "s" with size_t len from = zend_parse_paramters > 2. check if it doesn't overflow INT_MAX or when needed INT_MIN 3. cast = it to > int and pass the value to the lib function >=20 > If we have such functionality in ZPP, then it would be much simpler. I = would > imaging adding "i" for int and something like "q" (maybe different = letter :) ) for > string with int size. It would be basically the same as "l" and "s" = but there would > be an extra int overflow check which would fail if it's bigger / = smaller. That > would be very useful IMHO. >=20 Yeah, it is probably a good addition. If it is known that some API like = libxml2 requires integer which is 32-bit on LLP64, LP64 or alike so it = could overflow - ZPP could check it. It is useful in the case the exact = value is passed directly to the before mentioned API. If some = calculations, etc. need to be done before passing to that API, the = macros can still be useful. So maybe both a ZPP and macro change were useful and it would make sense = to go for an RFC first. I've started a draft here = https://wiki.php.net/rfc/range_checks_for_64_bit . Regards Anatol