This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libgcj java.io.ObjectInputStream patches


All,
I'm looking for some advise on how to formally submit these patches, or better yet, let one of you all who are maintaining java.io review and apply these simple changes on my behalf. Both patches apply to the java.io.ObjectInputStream.java. I'm sorry to say, it's nearly impossible to for me to publish the code that encountered these problems.


Patch 1
Stream corruption problems when reading an object that implements java.io.Externalizable.


The issue here is that readObject() was not properly looking for and reading TC_ENDBLOCK when the SC_BLOCK_DATA flag is set. This caused subsequent reads to fail because TC_ENDBLOCK was left unread on the stream.

According to the serialization standard, the TC_ENDBLOCK is used to signal the end of the object (when SC_BLOCK_DATA is set in the header), thus allowing extra data members that are present in the stream but left unread to be discarded. This allows the version of the object to change without breaking anything. My patch DOES NOT correctly handle the case where extra data needs to be discarded, but it does handle the simple case where the objects read exactly what they write without breaking.


Patch 2
The implementation of "public int read(byte[] data, int offset, int length) throws IOException" did not properly change to the next block nor did it always return the correct number of bytes that had been read.



The patch below and updated .java file (the one I've tested) can be found at: http://www.carnals.com/gcj.


Regards,
dave

--
Dave Carnal
Director of Engineering,
NetFuel, Inc.
+1-847.708.1560
dave@netfuel.com





> cvs diff -u ObjectInputStream.java
Index: ObjectInputStream.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/io/ObjectInputStream.java,v
retrieving revision 1.38
diff -u -r1.38 ObjectInputStream.java
--- ObjectInputStream.java      25 Nov 2004 03:47:01 -0000      1.38
+++ ObjectInputStream.java      8 Feb 2005 19:34:35 -0000
@@ -292,6 +292,7 @@

int handle = assignNewHandle(obj);

+ boolean has_write_method = osc.hasWriteMethod();
boolean read_from_blocks = ((osc.getFlags() & SC_BLOCK_DATA) != 0);


                 boolean oldmode = this.readDataFromBlock;
@@ -300,9 +301,13 @@

obj.readExternal(this);

+                 if (read_from_blocks)
+                     // Read TC_ENDBLOCKDATA !
+                     this.realInputStream.readByte()
+
                 if (read_from_blocks)
                   setBlockDataMode(oldmode);
-
+
                 ret_val = processResolution(osc, obj, handle);
                 break;
               } // end if (osc.realClassIsExternalizable)
@@ -905,7 +910,9 @@
  {
    if (this.readDataFromBlock)
      {
-       if (this.blockDataPosition + length > this.blockDataBytes)
+        int total = 0;
+
+       while (this.blockDataPosition + length > this.blockDataBytes)
         {
           int remain = this.blockDataBytes - this.blockDataPosition;
           if (remain != 0)
@@ -914,6 +921,7 @@
                                data, offset, remain);
               offset += remain;
               length -= remain;
+               total += remain;
             }
           readNextBlock ();
         }
@@ -922,7 +930,9 @@
                        data, offset, length);
       this.blockDataPosition += length;

-       return length;
+       total += length;
+
+       return total;
      }
    else
      return this.realInputStream.read(data, offset, length);

-

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]