You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by el...@apache.org on 2012/05/01 23:28:14 UTC
svn commit: r1332841 - in
/hadoop/common/branches/branch-2/hadoop-common-project: ./ hadoop-auth/
hadoop-common/ hadoop-common/src/main/docs/ hadoop-common/src/main/java/
hadoop-common/src/main/java/org/apache/hadoop/io/
hadoop-common/src/main/java/org...
Author: eli
Date: Tue May 1 21:28:13 2012
New Revision: 1332841
URL: http://svn.apache.org/viewvc?rev=1332841&view=rev
Log:
HADOOP-8275. svn merge -c 1332839 from trunk
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/ (props changed)
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-auth/ (props changed)
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/ (props changed)
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt (contents, props changed)
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/docs/ (props changed)
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/ (props changed)
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/DelegationKey.java
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/core/ (props changed)
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestWritableUtils.java
Propchange: hadoop/common/branches/branch-2/hadoop-common-project/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-common-project:r1332839
Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-auth/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-common-project/hadoop-auth:r1332839
Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common:r1332839
Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1332841&r1=1332840&r2=1332841&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt Tue May 1 21:28:13 2012
@@ -267,6 +267,9 @@ Release 2.0.0 - UNRELEASED
HADOOP-8325. Add a ShutdownHookManager to be used by different
components instead of the JVM shutdownhook (tucu)
+ HADOOP-8275. Range check DelegationKey length.
+ (Colin Patrick McCabe via eli)
+
BREAKDOWN OF HADOOP-7454 SUBTASKS
HADOOP-7455. HA: Introduce HA Service Protocol Interface. (suresh)
Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt:r1332839
Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/docs/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/docs:r1332839
Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/java:r1332839
Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java?rev=1332841&r1=1332840&r2=1332841&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/WritableUtils.java Tue May 1 21:28:13 2012
@@ -326,9 +326,41 @@ public final class WritableUtils {
* @return deserialized integer from stream.
*/
public static int readVInt(DataInput stream) throws IOException {
- return (int) readVLong(stream);
+ long n = readVLong(stream);
+ if ((n > Integer.MAX_VALUE) || (n < Integer.MIN_VALUE)) {
+ throw new IOException("value too long to fit in integer");
+ }
+ return (int)n;
}
-
+
+ /**
+ * Reads an integer from the input stream and returns it.
+ *
+ * This function validates that the integer is between [lower, upper],
+ * inclusive.
+ *
+ * @param stream Binary input stream
+ * @throws java.io.IOException
+ * @return deserialized integer from stream
+ */
+ public static int readVIntInRange(DataInput stream, int lower, int upper)
+ throws IOException {
+ long n = readVLong(stream);
+ if (n < lower) {
+ if (lower == 0) {
+ throw new IOException("expected non-negative integer, got " + n);
+ } else {
+ throw new IOException("expected integer greater than or equal to " +
+ lower + ", got " + n);
+ }
+ }
+ if (n > upper) {
+ throw new IOException("expected integer less or equal to " + upper +
+ ", got " + n);
+ }
+ return (int)n;
+ }
+
/**
* Given the first byte of a vint/vlong, determine the sign
* @param value the first byte
Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/DelegationKey.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/DelegationKey.java?rev=1332841&r1=1332840&r2=1332841&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/DelegationKey.java (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/delegation/DelegationKey.java Tue May 1 21:28:13 2012
@@ -41,6 +41,7 @@ public class DelegationKey implements Wr
private long expiryDate;
@Nullable
private byte[] keyBytes = null;
+ private static final int MAX_KEY_LEN = 1024 * 1024;
/** Default constructore required for Writable */
public DelegationKey() {
@@ -55,6 +56,10 @@ public class DelegationKey implements Wr
this.keyId = keyId;
this.expiryDate = expiryDate;
if (encodedKey != null) {
+ if (encodedKey.length > MAX_KEY_LEN) {
+ throw new RuntimeException("can't create " + encodedKey.length +
+ " byte long DelegationKey.");
+ }
this.keyBytes = encodedKey;
}
}
@@ -102,7 +107,7 @@ public class DelegationKey implements Wr
public void readFields(DataInput in) throws IOException {
keyId = WritableUtils.readVInt(in);
expiryDate = WritableUtils.readVLong(in);
- int len = WritableUtils.readVInt(in);
+ int len = WritableUtils.readVIntInRange(in, -1, MAX_KEY_LEN);
if (len == -1) {
keyBytes = null;
} else {
Propchange: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/core/
------------------------------------------------------------------------------
Merged /hadoop/common/trunk/hadoop-common-project/hadoop-common/src/test/core:r1332839
Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestWritableUtils.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestWritableUtils.java?rev=1332841&r1=1332840&r2=1332841&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestWritableUtils.java (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestWritableUtils.java Tue May 1 21:28:13 2012
@@ -44,6 +44,26 @@ public class TestWritableUtils extends T
assertEquals(vintlen, WritableUtils.getVIntSize(val));
assertEquals(vintlen, WritableUtils.decodeVIntSize(buf.getData()[0]));
}
+
+ public static void testReadInRange(long val, int lower,
+ int upper, boolean expectSuccess) throws IOException {
+ DataOutputBuffer buf = new DataOutputBuffer();
+ DataInputBuffer inbuf = new DataInputBuffer();
+ WritableUtils.writeVLong(buf, val);
+ try {
+ inbuf.reset(buf.getData(), 0, buf.getLength());
+ long val2 = WritableUtils.readVIntInRange(inbuf, lower, upper);
+ if (!expectSuccess) {
+ fail("expected readVIntInRange to throw an exception");
+ }
+ assertEquals(val, val2);
+ } catch(IOException e) {
+ if (expectSuccess) {
+ LOG.error("unexpected exception:", e);
+ fail("readVIntInRange threw an unexpected exception");
+ }
+ }
+ }
public static void testVInt() throws Exception {
testValue(12, 1);
@@ -61,5 +81,10 @@ public class TestWritableUtils extends T
testValue(-65536, 3);
testValue(65536, 4);
testValue(-65537, 4);
+ testReadInRange(123, 122, 123, true);
+ testReadInRange(123, 0, 100, false);
+ testReadInRange(0, 0, 100, true);
+ testReadInRange(-1, 0, 100, false);
+ testReadInRange(1099511627776L, 0, Integer.MAX_VALUE, false);
}
}