[SabreAMF] String references deserializing AMF3

Evert | Rooftop evertpot at gmail.com
Tue Nov 14 11:03:57 EST 2006


Thanks for your help Jim,

Looks good to me, I'll try to commit this in subversion tonight..
Also note there's a newer version now..

http://www.rooftopsolutions.nl/code/?a=d&p=SabreAMF

The 'latest' link will always be the latest version.. (still need to 
update that on osflash)

And.. you're contributions are really welcome! Right now its for the 
most part a one-man project.. I'm really hoping to find a bunch more 
good coders.. If you're up for that. it would be great!

Thanks again!
Evert

Jim Mischel wrote:
> There doesn't appear to be any messages at all in the archive, so I 
> don't know if anybody's caught this one.
>
> Working with SabreAMF yesterday (I downloaded and installed version 
> 0.3.2066 using PEAR as described on the SabreAMF page at 
> http://osflash.org/sabreamf), I noticed that there's a bug in reading 
> objects with string references.  The AMF spec at 
> http://www.osflash.org/amf3/index says, "...if the string is of zero 
> length it is not stored for later reference, therefore does not increase 
> the index counter."  The code in SabreAMF\AMF3\Deserializer.php, 
> however, does not take that special case into account.  It caches empty 
> strings.
>
> Also, when reading a string reference, the code does an additional, 
> unnecessary, right shift of the $strref value when accessing the array, 
> resulting in the wrong string being read.
>
> The fix is quite simple, as shown here:
>
> /**
>  * readString
>  *
>  * @return string
>  */
> public function readString() {
>
>     $strref = $this->readInt();
>
>     if (($strref & 0x01) == 0) {
>         $strref = $strref >> 1;
>         if ($strref>=count($this->storedStrings)) {
>             throw new Exception('Undefined string reference: ' . $strref);
>             return false;
>         }
>         // 2006-11-13 - jim - removed shift because shift has already 
> been done.
>         //printf("String reference %d\n", $strref);
>         return $this->storedStrings[$strref];
>         //return $this->storedStrings[$strref >> 1];
>     } else {
>         $strlen = $strref >> 1;
>         $str = $this->stream->readBuffer($strlen);
>         // 2006-11-13 - jim - if string is empty, don't save a reference.
>         if ($str != "")
>         {
>           $this->storedStrings[] = $str;
>           //printf("String #%d = %s\n", sizeof($this->storedStrings)-1, 
> $str);
>         }
>         return $str;
>     }
> }
>
> I've retained the old code (commented out), and also some debugging 
> output that I used to isolate the problem.
>
> Please let me know if this is the proper forum to report bugs and/or 
> supply fixes.  I'm hoping to use SabreAMF for a project, and am happy to 
> contribute to its ongoing development.
>
> Jim
>
>
>
>
> _______________________________________________
> sabreamf mailing list
> sabreamf at osflash.org
> http://osflash.org/mailman/listinfo/sabreamf_osflash.org
>   




More information about the sabreamf mailing list