Serious problems with script using large integer keys

General discussion on Zend Guard / Optimizer

Serious problems with script using large integer keys

Postby scheer on Wed Mar 16, 2016 7:00 pm

Hi!

I recently stumbled over a serious issue that breaks a lot of our code in one of our production environments.

We currently use php 5.5.x and Zend-Guard 7.0 64bit on RHEL 6.

The reproduction code ist as follows:

Code: Select all
<?php

$x32_key = '12345';
$x64_key = '9876543210';
$a = array( '12345' => 'value', '9876543210' => 'value' );

var_dump( $a );

# check access to array
echo "checking access with x32 key:\n";
var_dump( isset( $a[$x32_key] ) );
var_dump( array_key_exists( $x32_key, $a ) );

echo "\nchecking access with x64 key:\n";
var_dump( isset( $a[$x64_key] ) );
var_dump( array_key_exists( $x64_key, $a ) );


The expected output is:

array(2) {
[12345]=>
string(5) "value"
[9876543210]=>
string(5) "value"
}
checking access with x32 key:
bool(true)
bool(true)

checking access with x64 key:
bool(true)
bool(true)


Since '12345' and '9876543210' happen to be strings containing valid integers, they are converted to real integer keys.

Now, if I encode this script using zend guard 7.0 and run it again, the output is as follows:

array(2) {
[12345]=>
string(5) "value"
["9876543210"]=>
string(5) "value"
}
checking access with x32 key:
bool(true)
bool(true)

checking access with x64 key:
bool(false)
bool(false)


Strangely, the string '9876543210' now is NOT used as an integer key in the array. This is just not possible in an unencoded php script.

Since during runtime any attempt to access this key does again trigger the integer conversion, this array entry can not be accessed in any way.

If the integer stored in the string exceeds PHP_INT_MAX, it is again treated as string - which works as expected.

Any comments on this issue are appreciated!

Greetings

Nico
scheer
 
Posts: 6
Joined: Tue Jan 24, 2012 5:52 pm

Re: Serious problems with script using large integer keys

Postby zvika on Wed Jun 01, 2016 6:52 pm

Hello Nico
Thanks for reporting this and providing sample code and notes.

From first look, it seems like a 32-bit encoder running on 64-it system which facilitates the 32-bit Integer max 4 bytes.
For now I can suggest to fallback on 32-bit int routines if int_max_size=4.

We are checking this further with the product team to see if there is any workaround for current release.
I also answered to your support ticket, please check and reply.
Zvika Dror
Zend Support Team
User avatar
zvika
Zend Global Support
 
Posts: 969
Joined: Sun Dec 14, 2008 9:48 am


Return to Zend Guard / Optimizer

Who is online

Users browsing this forum: No registered users and 3 guests