Skip to Content »

FlashApe » Sending Negative Integers through AMFPHP

 Sending Negative Integers through AMFPHP

  • April 11th, 2008
  • 12:55 pm

There is a weird bug in AMFPHP regarding sending negative integers. If you try and send a number such as -87, it shows up as 4294967209 in php. I did some digging and found on the amfphp forums that it has to do with amfphp's readAmf3Int() method in AMFDeserialzer.php. Here is the updated function that was posted on the forum:

PHP:
  1. function readAmf3Int()
  2.     {
  3.         $res = 0;
  4.         $int = $this->readByte();
  5.        
  6.         if($int <128) {
  7.             return $int;
  8.         } else {
  9.             $int = ($int & 0x7f) <<7;
  10.            
  11.             $tmp = $this->readByte();
  12.            
  13.             if($tmp <128) {
  14.                 $int |= $tmp;
  15.             }else{
  16.                 $int = ($int | ($tmp & 0x7f)) <<7;
  17.                 $tmp = $this->readByte();
  18.                 if($tmp <128){
  19.                     $int |= $tmp;
  20.                 }else{
  21.                     $int = ($int | ($tmp & 0x7f)) <<8;
  22.                     $tmp = $this->readByte();
  23.                     $int |= $tmp;
  24.                 }
  25.             }
  26.         }
  27.  
  28.         $mask = 1<<28;
  29.         $res = -($int & $mask) | $int;
  30.  
  31.         return $res;
  32.     }

1 Person had this to say...

Gravatar
  • Evgeniy
  • May 8th, 2008
  • 9:38 pm

Thank's for this!

Want your say?

* Required fields. Your e-mail address will not be published on this site


You can use the following XHTML tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>