Archive for February, 2010

PHP Excel/Reader and not reading negative numbers on 64-bit machines

I recently switched from a 32-bit machine to a 64-bit machine.  I noticed that negative numbers were coming in around 1073741814.  This has to do with how bits are shifted on the different machines.

I have read that not patching these files will cause memory exhaustion, which can be critically bad in a production environment. 

I found a fix for that replace the GetInt4d function with

function GetInt4d($data, $pos) {
$_or_24 = ord($data[$pos+3]);

if ($_or_24>=128)
$_ord_24 = -abs((256-$_or_24) << 24);
$_ord_24 = ($_or_24&127) << 24;

return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | $_ord_24;

But what they failed to mention was that you also have to change the function _GetInt4d in the Excel/reader.php file as well.

I hope this helps someone (or myself) in the future.

This site hosted by - Find the best deals on Bowling Balls, Bowling Bags, Bowling Shoes, and Bowling Accessories.