Re: Overflow checks and integral vars comparison
| From: | Sherif Ramadan | Date: | Mon, 24 Aug 2015 14:06:00 +0000 |
| Subject: | Re: Overflow checks and integral vars comparison | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-87892@lists.php.net to get a copy of this message | ||
Hey Rowan,
Yup, I get it now. Sorry for the confusion.
I actually remember fixing a similar bug in pdo_sqlite a while back where
casting/translation between the two sizes caused such an issue. So I think
this would be pretty helpful.
On Sun, Aug 23, 2015 at 6:28 PM, Rowan Collins <rowan.collins@gmail.com>
wrote:
> 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.
>>
>
> 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).
>
> 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.
>
> 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.
>
> Regards,
>
> --
> Rowan Collins
> [IMSoP]
>
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>