History | Log In     View a printable version of the current page.  
Issue Details (XML)

Key: FP-601
Type: Bug Bug
Status: Resolved Resolved
Resolution: Not a Bug
Assignee: Edwin Wong
Reporter: Greg Jastrab
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Flash Player

Reading All bytes from an IDataInput into a ByteArray and calling readObject on that ByteArray causes RangeError #2006 when deserializing an array of anonymous objects

Created: 08/27/08 08:52 AM   Updated: 09/08/08 09:36 AM
Component/s: ActionScript General, Other
Security Level: Public (All JIRA Users )

File Attachments: 1. Zip Archive SerializationIssue.zip (5 kb)


Severity: Runtime Error
Reproducibility: Every Time
Discoverability: High
Found in Version: Flash Player 9 - 9_0_124_0
Affected OS(s): All OS Platforms - All
Steps to Reproduce:
Steps to reproduce:
1. Attaching as an AIR project, simply because that was the easiest way for me to quickly write it to a file and run it.
2. Build and run the AIR application.
3. Click the "Read Problem Serializer" button.
 
 Actual Results:
RangeError: Error #2006: The supplied index is out of bounds.
at flash.utils::ByteArray/readObject()
at io::ProblemSerializer/readExternal()[<path to environment>/SerializationIssue/src/io/ProblemSerializer.as:19]
at flash.filesystem::FileStream/readObject()
at SerializationIssue/readObj()[<path to environment>/SerializationIssue/src/SerializationIssue.mxml:40]
at SerializationIssue/___SerializationIssue_Button2_click()[<path to environment>/SerializationIssue/src/SerializationIssue.mxml:51]
 
 Expected Results:
 It to output the following into the TextArea as well as trace it out:
[ProblemSerializer]
 arr: [
{ obj: items, }

{ obj: in, }

{ obj: problem, }

{ obj: serializer, }
]


 
 Workaround (if any):
 
 
 
Language Found: English
Bugbase Id: none
Resolved by: Greg Jastrab
Participants: Edwin Wong, Greg Jastrab and Peter Farland
Browser: Safari 3.x


 All   Comments      Sort Order:
Greg Jastrab - [09/06/08 09:33 PM ]
So I've been digging into the AMF spec for a bit, and have a guess at what's going on here. I believe the reference tables used in AMF3 are not being utilized by the ByteArray after it has read all of the data.

When an externalizable class's readExternal method is invoked, are the reference tables used to look up the Object and Traits not available to a ByteArray that has read the remaining data out of the buffer?

It seems that if the reference tables are not available to/used by the ByteArray this would explain why

function readExternal(input:IDataInput):void {
  ...
  var arr:Array = input.readObject() as Array;
}

would work but

function readExternal(input:IDataInput):void {
  var ba:ByteArray = new ByteArray();
  input.readBytes(ba);
  ...
  var arr:Array = ba.readObject() as Array;
}

would not work.

Peter Farland - [09/07/08 10:43 PM ]
I commented on the original blog posting with the following:

Correct. I believe that ByteArray always expects AMF references to start at 0 and this is a problem for AMF data captured out of another stream (such as from an IExternalizable readObject() during deserialization of a NetConnection response).

You could process the raw ByteArray yourself using lower level read operations, but you would need to know what state the reference table was in (and unfortunately this is not obtainable from a NetConnection response). So instead that leaves you with completely custom serialization in the readObject()/writeObject() - such as buffering the IExternalizable content in a separate ByteArray first so that you know the references start at 0.

Greg Jastrab - [09/08/08 09:36 AM ]
Peter Farland confirmed <a href="http://blog.smartlogicsolutions.com/2008/08/27/serialization-errorbug-when-using-bytearray-readobject-iexternalizable-class/#comment-288">on my blog post</a> that this is due to the ByteArray not having access to the reference table the FileStream maintains.