harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lian...@apache.org
Subject svn commit: r513667 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/ObjectInputStream.java test/java/tests/api/java/io/ObjectInputStreamTest.java
Date Fri, 02 Mar 2007 09:03:28 GMT
Author: liangyx
Date: Fri Mar  2 01:03:27 2007
New Revision: 513667

URL: http://svn.apache.org/viewvc?view=rev&rev=513667
Log:
ObjectInputStream.readClassDescriptor does not valid the name of the class described by this
descriptor.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java?view=diff&rev=513667&r1=513666&r2=513667
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectInputStream.java
Fri Mar  2 01:03:27 2007
@@ -1757,7 +1757,11 @@
             ClassNotFoundException {
 
         ObjectStreamClass newClassDesc = new ObjectStreamClass();
-        newClassDesc.setName(input.readUTF());
+        String name = input.readUTF();
+        if ("".equals(name)) {
+            throw new IOException("The stream is corrupted.");
+        }
+        newClassDesc.setName(name);
         newClassDesc.setSerialVersionUID(input.readLong());
         newClassDesc.setFlags(input.readByte());
 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java?view=diff&rev=513667&r1=513666&r2=513667
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
Fri Mar  2 01:03:27 2007
@@ -17,6 +17,7 @@
 
 package tests.api.java.io;
 
+import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -783,13 +784,98 @@
 		oos.writeClassDescriptor(desc);
 		oos.close();
 		
-		ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        byte[] bytes = baos.toByteArray();
+		ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
 		ObjectIutputStreamWithReadDesc1 ois = new ObjectIutputStreamWithReadDesc1(
 				bais);
 		Object obj = ois.readClassDescriptor();
 		ois.close();
 		assertEquals(desc.getClass(), obj.getClass());
+        
+        //eof
+        bais = new ByteArrayInputStream(bytes);
+        ExceptionalBufferedInputStream bis = new ExceptionalBufferedInputStream(
+                bais);
+        ois = new ObjectIutputStreamWithReadDesc1(bis);
+
+        bis.setEOF(true);
+        
+        try {
+            obj = ois.readClassDescriptor();
+        } catch (IOException e) {
+            //e.printStackTrace();
+        } finally {
+            ois.close();
+        }
+        
+        //throw exception
+        bais = new ByteArrayInputStream(bytes);
+        bis = new ExceptionalBufferedInputStream(bais);
+        ois = new ObjectIutputStreamWithReadDesc1(bis);
+
+        bis.setException(new IOException());
+
+        try {
+            obj = ois.readClassDescriptor();
+        } catch (IOException e) {
+            //e.printStackTrace();
+        } finally {
+            ois.close();
+        }
+
+        //corrupt
+        bais = new ByteArrayInputStream(bytes);
+        bis = new ExceptionalBufferedInputStream(bais);
+        ois = new ObjectIutputStreamWithReadDesc1(bis);
+        
+        bis.setCorrupt(true);
+        
+        try {
+            obj = ois.readClassDescriptor();
+        } catch (IOException e) {
+            //e.printStackTrace();
+        } finally {
+            ois.close();
+        }
+
 	}
+    
+    static class ExceptionalBufferedInputStream extends BufferedInputStream {
+        private boolean eof = false;
+        private IOException exception = null; 
+        private boolean corrupt = false; 
+        
+        public ExceptionalBufferedInputStream(InputStream in) {
+            super(in);
+        }
+        
+        public int read() throws IOException {
+            if (exception != null) {
+                throw exception;
+            }
+            
+            if (eof) {
+                return -1;
+            }
+            
+            if (corrupt) {
+                return 0;
+            }
+            return super.read();
+        }
+        
+        public void setEOF(boolean eof) {
+            this.eof = eof;
+        }
+        
+        public void setException(IOException exception) {
+            this.exception = exception;
+        }
+        
+        public void setCorrupt(boolean corrupt) {
+            this.corrupt = corrupt;
+        }
+    }
 
     // Regression Test for Harmony-2402
     public void test_registerValidation() throws Exception {



Mime
View raw message