ionCube Logo
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


 
Post new topic   Reply to topic    ionCube Forum Index -> ionCube PHP Encoder

8.3.3 Linux - 64 bit Encoder - Overflow - 32 Bit Max Int

Author Message
yqit



Joined: 04 Feb 2016
Posts: 3

PostPosted: Thu Feb 04, 2016 2:57 pm    Post subject: 8.3.3 Linux - 64 bit Encoder - Overflow - 32 Bit Max Int Reply with quote

Hi ioncube Team,

we recenty updated our encoder machine from ubuntu 10.04 to 14.04 switching to ioncube_encoder_64 included in 8.3.3

The decoding machine, is:
PHP Version 5.6.14-0+deb8u1
System Linux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64
Build Date Oct 4 2015 16:12:10
Server API FPM/FastCGI
PHP API 20131106
PHP Extension 20131226
Zend Extension 220131226
Zend Extension Build API220131226,NTS
PHP Extension Build API20131226,NTS

The ionCube Loader version 5.0.23 for PHP 5.6 is already installed and encoded files should run without problems.

Our issue looks like an overflow at 32-bit max int:

Code:
$lastWorking = 2147483647;
echo '$lastWorking: '.$lastWorking.' (2147483647)<br />';
$firstNonWorking = 2147483648;
echo '$firstNonWorking: '.$firstNonWorking.' (2147483648)<br />';

$why = 2147483647 + 1;
echo '$why: '.$why.' (2147483647 + 1 = 2147483648)<br />';

Output:
$lastWorking: 2147483647 (2147483647)
$firstNonWorking: -2147483648 (2147483648)
$why: 2147483648 (2147483647 + 1 = 2147483648)

Using the non-encrypted source echos the correct:
$firstNonWorking: 2147483648 (2147483648)


How can we fix this?

Thanks in advance,
Marc
Back to top
View user's profile Send private message
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2788

PostPosted: Fri Feb 05, 2016 3:31 pm    Post subject: Reply with quote

This is to do with word size. One of the flaws in the PHP engine is that it uses the long C type to represent integers, and as this has a different word size on different architectures, PHP code may behave differently on 32 and 64 bit systems once number get large. To make PHP code 64 bit clean, you need to avoid numbers that rely on a word size greater than 32. Encoded files are 32 bit so as to work the same on 32 and 64 bit systems, which explains the results you have. If you need more guidance the support team can assist at https://support.ioncube.com
_________________
Community Admin
Back to top
View user's profile Send private message
yqit



Joined: 04 Feb 2016
Posts: 3

PostPosted: Wed Feb 10, 2016 11:23 am    Post subject: Reply with quote

Hi liaison,

thanks for your reply.

The fact, that our test code is working unencrypted on the target machine, points out that there is just the ioncode encoder (8.3.3. - 64 Bit) that cant deal with numbers greater than 32 bit.

The advice not to use 64 bit when using 64 bit sounds little bit funny to me.

Using unencrypted or using ioncode encoder 8.3.3. - 32Bit works fine, so my advice is:
Do NOT use ioncode encoder 8.3.3. - 64 Bit.

Marc
Back to top
View user's profile Send private message
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2788

PostPosted: Wed Feb 10, 2016 3:44 pm    Post subject: Reply with quote

"the ioncode encoder (8.3.3. - 64 Bit) that cant deal with numbers greater than 32 bit"

Ironically it's the opposite in that the 64 bit Encoder *can* deal with 64 bit numbers, and this is why you get the unexpected result. 2147483648 needs to be stored as a float and would be with the 32 bit Encoder and 32 bit PHP because the value exceeds the maximum possible positive 32 bit integer when using 2's complement arithmetic. Because the 64 bit Encoder can store it as an int due to the word size dependency that the PHP compiler has (using a C long rather than an C int), the 64 bit value comes out as negative when stored in the platform independent format.

Note, this only affects parsing of literal values in the source code itself that are greater than 2^31-1, which is particularly rare to find in PHP code. So if your code uses literal values > 2^31-1 then using the 32 bit Encoder is best, but otherwise it makes no difference and either is fine.
_________________
Community Admin
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ionCube Forum Index -> ionCube PHP Encoder All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum