Hi Jakub,

> -----Original Message-----
> From: jakub....@gmail.com [mailto:jakub....@gmail.com] On Behalf Of Jakub
> Zelenka
> Sent: Sunday, August 23, 2015 8:29 PM
> To: Anatol Belski <anatol....@belski.net>
> Cc: Dmitry Stogov <dmi...@php.net>; Xinchen Hui <xinche...@zend.com>;
> Nikita Popov <nikita....@gmail.com>; Pierre Joye <pierre....@gmail.com>;
> Bob Weinand <bobw...@hotmail.com>; Matt Wilmas
> <php_li...@realplain.com>; PHP internals list <internals@lists.php.net>
> Subject: [PHP-DEV] Re: Overflow checks and integral vars comparison
> 
> Hi Anatol,
> 
> On Fri, Aug 21, 2015 at 9:41 AM, Anatol Belski <anatol....@belski.net>
> 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.
> 
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


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to