Merge "Adjust cookie max-age from expires time calculation."
am: f967e2a6dd
Change-Id: I6d0c1c9d4d15a8964e3dcae950ba55424b0882c7
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/ObjectInputStream2Test.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/ObjectInputStream2Test.java
index e81224a..af5fce5 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/ObjectInputStream2Test.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/ObjectInputStream2Test.java
@@ -17,10 +17,8 @@
package org.apache.harmony.tests.java.io;
-import dalvik.system.DexFile;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidClassException;
@@ -29,9 +27,6 @@
import java.io.ObjectStreamClass;
import java.io.ObjectStreamException;
import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.nio.file.Files;
-import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import junit.framework.TestCase;
@@ -215,54 +210,4 @@
// Excpected
}
}
-
- // http://b/29721023
- public void test_sameName() throws Exception {
- // Load class from dex, it's not possible to create a class with same-named
- // fields in java (but it's allowed in dex).
- File sameFieldNames = File.createTempFile("sameFieldNames", ".dex");
- InputStream dexIs = this.getClass().getClassLoader().
- getResourceAsStream("tests/api/java/io/sameFieldNames.dex");
- assertNotNull(dexIs);
-
- Class<?> clazz = null;
-
- // Get the class object
- try {
- Files.copy(dexIs, sameFieldNames.toPath(), StandardCopyOption.REPLACE_EXISTING);
- DexFile dexFile = new DexFile(sameFieldNames);
- clazz = dexFile.loadClass("sameFieldNames", getClass().getClassLoader());
- dexFile.close();
- } finally {
- if (sameFieldNames.exists()) {
- sameFieldNames.delete();
- }
- }
-
- // Create class instance, fill it with content
- Object o1 = clazz.getConstructor().newInstance();
- int v = 123;
- for(Field f : clazz.getFields()) {
- if (f.getType() == Integer.class) {
- f.set(o1, new Integer(v++));
- } else if (f.getType() == Long.class) {
- f.set(o1, new Long(v++));
- }
- }
-
- // Serialize and deserialize
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(o1);
- oos.close();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
- baos.toByteArray()));
- Object o2 = ois.readObject();
- ois.close();
-
- // Compare content
- for(Field f : clazz.getFields()) {
- assertEquals(f.get(o1), f.get(o2));
- }
- }
}
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/ObjectStreamClassTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/ObjectStreamClassTest.java
index 6253b6b..bebeb6e 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/ObjectStreamClassTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/io/ObjectStreamClassTest.java
@@ -17,23 +17,17 @@
package org.apache.harmony.tests.java.io;
-import dalvik.system.DexFile;
import dalvik.system.VMRuntime;
import java.io.Externalizable;
-import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.ObjectStreamClass;
import java.io.ObjectStreamField;
import java.io.Serializable;
-import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.nio.file.Files;
-import java.nio.file.StandardCopyOption;
import junit.framework.TestCase;
public class ObjectStreamClassTest extends TestCase {
@@ -325,27 +319,4 @@
hasStaticInitializer.invoke(null, NoClinitChildWithNoClinitParent.class,
true /* checkSuperclass */));
}
-
- // http://b/29721023
- public void testClassWithSameFieldName() throws Exception {
- // Load class from dex, it's not possible to create a class with same-named
- // fields in java (but it's allowed in dex).
- File sameFieldNames = File.createTempFile("sameFieldNames", ".dex");
- InputStream dexIs = this.getClass().getClassLoader().
- getResourceAsStream("tests/api/java/io/sameFieldNames.dex");
- assertNotNull(dexIs);
-
- try {
- Files.copy(dexIs, sameFieldNames.toPath(), StandardCopyOption.REPLACE_EXISTING);
- DexFile dexFile = new DexFile(sameFieldNames);
- Class<?> clazz = dexFile.loadClass("sameFieldNames", getClass().getClassLoader());
- ObjectStreamClass osc = ObjectStreamClass.lookup(clazz);
- assertEquals(4, osc.getFields().length);
- dexFile.close();
- } finally {
- if (sameFieldNames.exists()) {
- sameFieldNames.delete();
- }
- }
- }
}
diff --git a/luni/src/test/java/libcore/javax/security/auth/x500/X500PrincipalTest.java b/luni/src/test/java/libcore/javax/security/auth/x500/X500PrincipalTest.java
index 4f5d658..5471b1f 100644
--- a/luni/src/test/java/libcore/javax/security/auth/x500/X500PrincipalTest.java
+++ b/luni/src/test/java/libcore/javax/security/auth/x500/X500PrincipalTest.java
@@ -120,6 +120,30 @@
expectExceptionInDNConstructor("l=\\g0");
}
+ public void testNegativeLen() {
+ try {
+ X500Principal p = new X500Principal(new byte[]{
+ 0x30, // DerValue.tag_Sequence read in DerValue#getSequence
+ 9, // Length of the vector. read in readVector.
+ // DerInputStream.getLength will just return this as 10 & 0x80 == 0
+ -1, // Tag of the first value in the sequencevalue. Convenient so that it
+ // doesn't hold DerIndefLenConverter.isEOC()
+ (byte) 0x80, // Encoding in indefinite form
+ -1, // Second tag to be read by DerIndefLenConverter
+ (byte) 0x84, // Second length byte to be read, 0x80 means long form, 4 bytes
+ (byte) 0xff, // Length to be read by DerIndefLenConverter, -6, will move the
+ // buffer position to the second tag
+ (byte) 0xff,
+ (byte) 0xff,
+ (byte) -6,
+ 0, // Needed as otherwise it's detected that there's nothing after
+ // the length
+ });
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
private void expectExceptionInDNConstructor(String dn) {
try {
X500Principal principal = new X500Principal(dn);
diff --git a/ojluni/src/main/java/java/util/zip/ZipFile.java b/ojluni/src/main/java/java/util/zip/ZipFile.java
old mode 100755
new mode 100644
diff --git a/ojluni/src/main/java/sun/security/util/DerIndefLenConverter.java b/ojluni/src/main/java/sun/security/util/DerIndefLenConverter.java
index 78d9e30..cbd5ecc 100644
--- a/ojluni/src/main/java/sun/security/util/DerIndefLenConverter.java
+++ b/ojluni/src/main/java/sun/security/util/DerIndefLenConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -156,12 +156,18 @@
}
if (isLongForm(lenByte)) {
lenByte &= LEN_MASK;
- if (lenByte > 4)
+ if (lenByte > 4) {
throw new IOException("Too much data");
- if ((dataSize - dataPos) < (lenByte + 1))
+ }
+ if ((dataSize - dataPos) < (lenByte + 1)) {
throw new IOException("Too little data");
- for (int i = 0; i < lenByte; i++)
+ }
+ for (int i = 0; i < lenByte; i++) {
curLen = (curLen << 8) + (data[dataPos++] & 0xff);
+ }
+ if (curLen < 0) {
+ throw new IOException("Invalid length bytes");
+ }
} else {
curLen = (lenByte & LEN_MASK);
}
@@ -188,10 +194,15 @@
}
if (isLongForm(lenByte)) {
lenByte &= LEN_MASK;
- for (int i = 0; i < lenByte; i++)
+ for (int i = 0; i < lenByte; i++) {
curLen = (curLen << 8) + (data[dataPos++] & 0xff);
- } else
+ }
+ if (curLen < 0) {
+ throw new IOException("Invalid length bytes");
+ }
+ } else {
curLen = (lenByte & LEN_MASK);
+ }
writeLength(curLen);
writeValue(curLen);
}
diff --git a/ojluni/src/main/java/sun/security/util/DerInputStream.java b/ojluni/src/main/java/sun/security/util/DerInputStream.java
index 8f51439..dae8afd 100644
--- a/ojluni/src/main/java/sun/security/util/DerInputStream.java
+++ b/ojluni/src/main/java/sun/security/util/DerInputStream.java
@@ -604,6 +604,10 @@
value <<= 8;
value += 0x0ff & in.read();
}
+ if (value < 0) {
+ throw new IOException("DerInputStream.getLength(): "
+ + "Invalid length bytes");
+ }
}
return value;
}