bug in function getCStringLenght
Brought to you by:
sephiroth_tmm
I found two bug in this function
1st) In case serialization string is length of string bigger
like number 9 (Exam s:13:")you start parse still from
position 5 -> This means you start parsing character "
2nd) I think you should substract -1 in both cases
charCodeAt>128 and charCodeAt>255. Finally function
should look like:
private function getCStringLenght (str:String):Number {
var len:Number = parseInt (this.buffer.substr (2,
this.buffer.indexOf (":", 3) - 2));
var i:Number;
var j:Number = len;
var startIndex:Number;
var cstr = this.buffer;
startIndex=4+len.toString().length;
for (i = 0; i < j; i++){
if (cstr.charCodeAt (i + startIndex) > 128){
j = j - 1
}
}
return j;
}; // getCStringLenght
Logged In: NO
I haven't varified the first bug but I located the second
problem and I agree with this implmenetation. This function
needs to be updated.
Regards,
D
Logged In: YES
user_id=634570
i will put this modification into the next release.
P.S. I've just switched to SVN
This is pretty old but the exact same bug exists for double/int's where the length is > 9.
It makes the code very unstable if your using doubles in arrays and/objects.
Also the object support is very weak (it doesn't support classes just very simple objects).
I added more complicated support using new _global[className] instead of new Object() the problem
private function unserialize_internal(obj:String):Object{
var _type:String = obj.charAt(0);
var _value:Array;
var offset = 0;
switch(_type){
case "d":
_value = parse_double();
offset = _value[0] + length(_type) + 2;
break;
case "i":
_value = parse_int();
offset = _value[0] + length(_type) + 2;
break;
case "b":
_value = parse_boolean();
offset = _value[0] + length(_type) + length(_value[0].toString())) + 1;
break;
case "s":
_value = parse_string();
offset = _value[0] + length(_type) + length(_value[0].toString())) + 1;
break;
case "a":
_value = parse_array();
offset = _value[0] + length(_type) + length(_value[0].toString())) + 1;
break;
case "O":
_value = parse_object();
offset = _value[0] + length(_type) + length(_value[0].toString())) + 1;
break;
case "N":
default:
break;
}
if(_value[0] != -1){
this.buffer = this.buffer.substr (
this.buffer.indexOf (";", offset );
}
return _value[1];
}; // unserialize_internal