From 3f2468e7a1c192fc0f8254ab3f38a2c279724302 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 24 Sep 2009 20:09:35 +0000 Subject: [PATCH] Oh crap, let's make ObjectOutputStream protect against fuckup, too. Note that we're using ints instead of units for offset/length. Does anyone really need a byte array larger than 2^31? And if so, wouldn't you then also be within sight of busting 2^32? Why not make it a Number and support up to 2^53? Number is no guarantee of a desire for a floating-point value in the flash libraries, see Graphics.lineStyle()'s first parameter. Actionscript, you fail for not having long. And... I said I wasn't going to bitch at Adobe/Macromedia any more but this is a total FAIL. 0 is a valid length. Everyone knows this. Can you imagine if they picked a different constant? length: the number of bytes to read, unless it's 9, in which case it reads *all* the bytes. Your code should check to see if you're about to read 9 bytes, and instead read 8 in one go and then a follow-on byte. uint.MAX_VALUE would have made tons more sense. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5968 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/io/ObjectInputStream.as | 3 +-- src/as/com/threerings/io/ObjectOutputStream.as | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/as/com/threerings/io/ObjectInputStream.as b/src/as/com/threerings/io/ObjectInputStream.as index 1a9c81b6f..8d910a108 100644 --- a/src/as/com/threerings/io/ObjectInputStream.as +++ b/src/as/com/threerings/io/ObjectInputStream.as @@ -202,8 +202,7 @@ public class ObjectInputStream * Read bytes into the byte array. If length is not specified, then * enough bytes to fill the array (from the offset) are read. */ - public function readBytes (bytes :ByteArray, offset :uint = 0, - length :int = -1) :void + public function readBytes (bytes :ByteArray, offset :int = 0, length :int = -1) :void //throws IOError { // if no length specified then fill the ByteArray diff --git a/src/as/com/threerings/io/ObjectOutputStream.as b/src/as/com/threerings/io/ObjectOutputStream.as index a8cbb9d60..0901c01b7 100644 --- a/src/as/com/threerings/io/ObjectOutputStream.as +++ b/src/as/com/threerings/io/ObjectOutputStream.as @@ -164,11 +164,15 @@ public class ObjectOutputStream _targ.writeByte(value); } - public function writeBytes (bytes :ByteArray, offset :uint=0, - length :uint = 0) :void + public function writeBytes (bytes :ByteArray, offset :int = 0, length :int = -1) :void //throws IOError { - _targ.writeBytes(bytes, offset, length); + if (length == -1) { + length = bytes.length - offset; + } + if (length > 0) { + _targ.writeBytes(bytes, offset, length); + } } public function writeDouble (value :Number) :void