pupsnow / as3-commons

Automatically exported from code.google.com/p/as3-commons
1 stars 0 forks source link

doubles[++i] = _byteStream.readDouble(); #122

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I found a bug in AbstractAbcDeserializer.as as below.

doubles[++i] = _byteStream.readDouble();

This code should be read in little-endian order.
But the byteStream.endian was big-endian.

Original issue reported on code.google.com by nibiiron...@gmail.com on 19 Apr 2012 at 2:56

GoogleCodeExporter commented 9 years ago
Hi there,

you're not giving much information here. Where did the bytearray come from that 
you're trying to read? The deserializer doesn't change the incoming bytearray, 
it is assumed that the array is in big-endian order. So what do you mean 
precisely?

cheers,

Roland

Original comment by ihatelivelyids on 23 Apr 2012 at 9:38

GoogleCodeExporter commented 9 years ago
Hi Roland

Sorry to be insufficient information. To modify abc data in a swf file, I got 
abc data (as a com.codeazur.as3swf.tags.TagDoABC class) from loaded swf file. 
Then I tried below codes.
  var abcDeserializer:AbcDeserializer = new AbcDeserializer(tagDoABC.bytes);
  var abcFile:AbcFile = abcDeserializer.deserialize();
  // some codes.
  var abcSerializer:AbcSerializer = new AbcSerializer();
  tagDoABC.bytes.length = 0;
  tagDoABC.bytes.writeBytes(abcSerializer.serializeAbcFile(abcFile));

Although no error was appeared, unexpected data were showed when I dumped the 
modified abc data like below.
  pushdouble 0.0235836493923 * 10^-69

The value was clearly wrong. So I checked the definition of double in AVM2 
overview.
http://www.adobe.com/content/dam/Adobe/en/devnet/actionscript/articles/avm2overv
iew.pdf

The overview saying that "Multi-byte primitive data are stored in little-endian 
order".

So I checked the deserialize method, and I found that _byteStream.readDouble() 
in line 144 of deserializeConstantPool method of AbstractAbcDeserializer class 
was performed in big-endian order.

Then I added below code just before readDouble method and the abnormal value 
was fixed.
  _byteStream.endian = Endian.LITTLE_ENDIAN;

I am using:
as3commons-bytecode-1.1.1.swc

Compiling with sdk 4.5

On Windows XP

Original comment by nibiiron...@gmail.com on 23 Apr 2012 at 2:09

GoogleCodeExporter commented 9 years ago
Hey there,

the serializer creates a ByteArray that has its endian property set to 
Endian.LITTLE_ENDIAN, so I'm guessing the the bytearray you receive from the 
as3swf library has been set to BIG_ENDIAN. Can you check that?
On my end I can't figure out what I could be doing wrong... I guess I could 
force the property on any incoming bytearrays to Endian.LITTLE_ENDIAN as well...

Roland

Original comment by ihatelivelyids on 24 Apr 2012 at 6:01