Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87884 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54036 invoked from network); 23 Aug 2015 18:28:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Aug 2015 18:28:52 -0000 Authentication-Results: pb1.pair.com header.from=jakub.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jakub.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.195 as permitted sender) X-PHP-List-Original-Sender: jakub.php@gmail.com X-Host-Fingerprint: 209.85.213.195 mail-ig0-f195.google.com Received: from [209.85.213.195] ([209.85.213.195:32970] helo=mail-ig0-f195.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0E/E4-27100-1E01AD55 for ; Sun, 23 Aug 2015 14:28:50 -0400 Received: by igbjg10 with SMTP id jg10so5807227igb.0 for ; Sun, 23 Aug 2015 11:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=xeqcXiL0gGeMq214/r1m7MekJheAjJr1HD9Q61S1Ens=; b=WonNTX508pGlfkPCS1B61da+6kdsnloB2A11ONy/4ODJXoYhA1k/LJmynyNnfQ+/vO ht2iG2C6k6/2WFVywFVE6LkibKTZLlm7ZIt7aa1ElcznnhE6jlkoZ0rdoMFBWsJtBYon sKKqR/kBoOdtJyjdRlVQ4no6+yMXQInwU6hpMSmd5y1IL3MqSFaRIW4WRS3rvBkRt+DW HyCpnTMFJB4pI3JTy0jVfUuGXQgM7vwm1nZ9zEWpaWCmzclO6QSKoVR7ulS7GmXWlBRO bOtFOhgj0vLrnFhxrVGoXJnqctlZLsgjiUMiAhTETT8bBJN2rJYPk8tpuCFNmDlK819b yWzw== MIME-Version: 1.0 X-Received: by 10.50.70.67 with SMTP id k3mr12171028igu.76.1440354527209; Sun, 23 Aug 2015 11:28:47 -0700 (PDT) Sender: jakub.php@gmail.com Received: by 10.107.155.70 with HTTP; Sun, 23 Aug 2015 11:28:47 -0700 (PDT) In-Reply-To: <02a601d0dbed$2c828df0$8587a9d0$@belski.net> References: <02a601d0dbed$2c828df0$8587a9d0$@belski.net> Date: Sun, 23 Aug 2015 19:28:47 +0100 X-Google-Sender-Auth: z5ebvBsJeLQP6_c8Cdg4s2bqtOY Message-ID: To: Anatol Belski Cc: Dmitry Stogov , Xinchen Hui , Nikita Popov , Pierre Joye , Bob Weinand , Matt Wilmas , PHP internals list Content-Type: multipart/alternative; boundary=047d7b3a8a64f1f015051dfeab39 Subject: Re: Overflow checks and integral vars comparison From: bukka@php.net (Jakub Zelenka) --047d7b3a8a64f1f015051dfeab39 Content-Type: text/plain; charset=UTF-8 Hi Anatol, On Fri, Aug 21, 2015 at 9:41 AM, Anatol Belski wrote: > 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 == 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. 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: 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 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. Cheers Jakub --047d7b3a8a64f1f015051dfeab39--