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 om...@apache.org on 2011/03/04 04:48:40 UTC
svn commit: r1077175 - in
/hadoop/common/branches/branch-0.20-security-patches/src:
core/org/apache/hadoop/fs/HarFileSystem.java
test/org/apache/hadoop/fs/TestHarFileSystem.java
Author: omalley
Date: Fri Mar 4 03:48:40 2011
New Revision: 1077175
URL: http://svn.apache.org/viewvc?rev=1077175&view=rev
Log:
commit e631bf277592a4e8a2f4f626672edebd0e00163b
Author: Mahadev Konar <ma...@cdev6022.inktomisearch.com>
Date: Thu Feb 18 22:12:29 2010 +0000
HADOOP:6550 from http://issues.apache.org/jira/secure/attachment/12436045/c6560_20100212_y0.20.patch
+++ b/YAHOO-CHANGES.txt
+ HADOOP-6560. HarFileSystem throws NPE for har://hdfs-/foo (nicholas via
+ mahadev)
+
Modified:
hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/HarFileSystem.java
hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestHarFileSystem.java
Modified: hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/HarFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/HarFileSystem.java?rev=1077175&r1=1077174&r2=1077175&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/HarFileSystem.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/fs/HarFileSystem.java Fri Mar 4 03:48:40 2011
@@ -181,12 +181,20 @@ public class HarFileSystem extends Filte
return FileSystem.getDefaultUri(conf);
}
String host = rawURI.getHost();
- String[] str = host.split("-", 2);
- if (str[0] == null) {
- throw new IOException("URI: " + rawURI + " is an invalid Har URI.");
- }
- String underLyingScheme = str[0];
- String underLyingHost = (str.length > 1)? str[1]:null;
+ if (host == null) {
+ throw new IOException("URI: " + rawURI
+ + " is an invalid Har URI since host==null."
+ + " Expecting har://<scheme>-<host>/<path>.");
+ }
+ int i = host.indexOf('-');
+ if (i < 0) {
+ throw new IOException("URI: " + rawURI
+ + " is an invalid Har URI since '-' not found."
+ + " Expecting har://<scheme>-<host>/<path>.");
+ }
+ final String underLyingScheme = host.substring(0, i);
+ i++;
+ final String underLyingHost = i == host.length()? null: host.substring(i);
int underLyingPort = rawURI.getPort();
String auth = (underLyingHost == null && underLyingPort == -1)?
null:(underLyingHost+":"+underLyingPort);
Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestHarFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestHarFileSystem.java?rev=1077175&r1=1077174&r2=1077175&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestHarFileSystem.java (original)
+++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/fs/TestHarFileSystem.java Fri Mar 4 03:48:40 2011
@@ -294,4 +294,24 @@ public class TestHarFileSystem extends T
assertTrue("number of bytes left should be -1", reduceIn.read(b) == -1);
reduceIn.close();
}
+
+ public void testHarUri() {
+ final Configuration conf = new Configuration();
+ checkInvalidPath("har://hdfs-/foo.har", conf);
+ checkInvalidPath("har://hdfs/foo.har", conf);
+ checkInvalidPath("har://-hdfs/foo.har", conf);
+ checkInvalidPath("har://-/foo.har", conf);
+ }
+
+ static void checkInvalidPath(String s, Configuration conf) {
+ System.out.println("\ncheckInvalidPath: " + s);
+ final Path p = new Path(s);
+ try {
+ p.getFileSystem(conf);
+ fail(p + " is an invalid path.");
+ } catch (IOException e) {
+ System.out.println("GOOD: Got an exception.");
+ e.printStackTrace(System.out);
+ }
+ }
}