#13 AMD 64 Integer overflow / signum fix

open
nobody
None
5
2006-05-12
2006-05-12
Andreas Rehm
No

The function GetInt4d in oleread.inc should be replaced
with:

----

function GetInt4d($data, $pos) {
// Hacked by Andreas Rehm 2006 to ensure correct
result of the <<24 block on 32 and 64bit systems
$_or_24 = ord($data[$pos+3]);
if ($_or_24>=128) $_ord_24 = -abs((256-$_or_24) << 24);
else $_ord_24 = ($_or_24&127) << 24;

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

----

Otherwise you will get a dead loop in oleread.inc on AMD64.

Regards,
Andreas Rehm

Discussion

  • Logged In: NO

    Spot on, nice fix - this had me going nuts for ages!!

     
  • Logged In: NO

    tnx a lot, solved my problem.

     
  • Logged In: YES
    user_id=1352571
    Originator: NO

    Thanks so much for this, excellent job

     
  • Logged In: NO

    Thanks for fix, my symptom was exhausting memory.

     
  • Logged In: NO

    I think you are a real genius.

    I can't say anything except that.

    Thanks.

     
  • Logged In: NO

    Do Not function in Intel XEON (QUAD CORE - 64 bit)

     
  • Andreas Rehm
    Andreas Rehm
    2008-06-26

    Logged In: YES
    user_id=604599
    Originator: YES

    This fix should work on any 32 and 64bit CPU's. Only 16 bit will be an issue - but who works with 16bit?

    Regards,
    Andreas

     
  • Logged In: NO

    You, are a god.

     
  • I think that's better to use :

    function _GetInt4d($data, $pos) {
    $d = unpack('Vhash32', substr($data, $pos, 4));
    return $d['hash32'];
    }

    like that dead loop is over.

    Regards,
    Sylvain