harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmar...@apache.org
Subject svn commit: r606724 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/DataInputStream.java test/api/common/tests/api/java/io/DataInputStreamTest.java
Date Mon, 24 Dec 2007 18:58:53 GMT
Author: mmarkov
Date: Mon Dec 24 10:58:51 2007
New Revision: 606724

URL: http://svn.apache.org/viewvc?rev=606724&view=rev
Log:
Applied patch for HARMONY-5336: [classlib][luni] StackOverflow in DataInputStream.readUTF(DataInput)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/DataInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java?rev=606724&r1=606723&r2=606724&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/DataInputStream.java
Mon Dec 24 10:58:51 2007
@@ -413,10 +413,13 @@
 
 
     String decodeUTF(int utfSize) throws IOException {
+        return decodeUTF(utfSize, this);
+    }
 
+    private static String decodeUTF(int utfSize, DataInput in) throws IOException {
         byte[] buf = new byte[utfSize];
         char[] out = new char[utfSize];
-        readFully(buf, 0, utfSize);
+        in.readFully(buf, 0, utfSize);
 
         return Util.convertUTF8WithBuf(buf, out, 0, utfSize);
     }
@@ -434,7 +437,7 @@
      * @see DataOutput#writeUTF(java.lang.String)
      */
     public static final String readUTF(DataInput in) throws IOException {
-        return in.readUTF();
+        return decodeUTF(in.readUnsignedShort(), in);
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/DataInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/DataInputStreamTest.java?rev=606724&r1=606723&r2=606724&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/DataInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/io/DataInputStreamTest.java
Mon Dec 24 10:58:51 2007
@@ -18,6 +18,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.DataInput;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.EOFException;
@@ -540,6 +541,67 @@
                 assertTrue("Incorrect string read", dis.readUTF().equals(unihw));
 	}
 
+    static class TestDataInputStream implements DataInput {
+        public boolean readBoolean() throws IOException {
+            return false;
+        }
+
+        public byte readByte() throws IOException {
+            return (byte) 0;
+        }
+
+        public char readChar() throws IOException {
+            return (char) 0;
+        }
+
+        public double readDouble() throws IOException {
+            return 0.0;
+        }
+
+        public float readFloat() throws IOException {
+            return (float) 0.0;
+        }
+
+        public void readFully(byte[] buffer) throws IOException {
+        }
+
+        public void readFully(byte[] buffer, int offset, int count)
+            throws IOException {
+        }
+
+        public int readInt() throws IOException {
+            return 0;
+        }
+
+        public String readLine() throws IOException {
+            return null;
+        }
+
+        public long readLong() throws IOException {
+            return (long) 0;
+        }
+
+        public short readShort() throws IOException {
+            return (short) 0;
+        }
+
+        public int readUnsignedByte() throws IOException {
+            return 0;
+        }
+
+        public int readUnsignedShort() throws IOException {
+            return 0;
+        }
+
+        public String readUTF() throws IOException {
+            return DataInputStream.readUTF(this);
+        }
+
+        public int skipBytes(int count) throws IOException {
+            return 0;
+        }
+    }
+
 	/**
 	 * @tests java.io.DataInputStream#readUTF(java.io.DataInput)
 	 */
@@ -553,6 +615,9 @@
                                 dis.available() == unihw.length() + 2);
                 assertTrue("Incorrect string read", DataInputStream.readUTF(dis)
                                 .equals(unihw));
+
+                // Regression test for HARMONY-5336
+                new TestDataInputStream().readUTF();
 	}
 
 	/**



Mime
View raw message