Bladeren bron

commit 7c5f362bb4182b75602a32b601c4064b70e81318
Author: Arun C Murthy <acmurthy@apache.org>
Date: Thu May 13 23:54:54 2010 -0700

MAPREDUCE-1442. Fixed regex in job-history related to parsing Counter values. Contributed by Luke Lu.

From https://issues.apache.org/jira/secure/attachment/12444349/mr-1442-y20s-v1.patch

+++ b/YAHOO-CHANGES.txt
+ MAPREDUCE-1442. Fixed regex in job-history related to parsing Counter
+ values. (Luke Lu via acmurthy)
+


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-patches@1077462 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 jaren geleden
bovenliggende
commit
3ed5589d2e

+ 1 - 1
src/mapred/org/apache/hadoop/mapred/JobHistory.java

@@ -95,7 +95,7 @@ public class JobHistory {
 
   static final String KEY = "(\\w+)";
   // value is any character other than quote, but escaped quotes can be there
-  static final String VALUE = "[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*"; 
+  static final String VALUE = "[^\"\\\\]*+(?:\\\\.[^\"\\\\]*+)*+";
   
   static final Pattern pattern = Pattern.compile(KEY + "=" + "\"" + VALUE + "\"");
   

+ 14 - 3
src/test/org/apache/hadoop/mapred/TestJobHistoryParsing.java

@@ -73,7 +73,15 @@ public class TestJobHistoryParsing  extends TestCase {
                     "\t\b\n\f\"\n in it";
     String value4 = "Value ends with escape\\";
     String value5 = "Value ends with \\\" \\.\n";
-    
+    StringBuilder sb = new StringBuilder("Longer value with many escaped "+
+        "chars, which tends to overflow the stack of brittle regex parsers");
+    for (int i = 0; i < 1000; ++i) {
+      sb.append(",");
+      sb.append("\\split.");
+      sb.append(i);
+    }
+    String value6 = sb.toString();
+
     // Log the history version
     JobHistory.MetaInfoManager.logMetaInfo(historyWriter);
     
@@ -82,8 +90,10 @@ public class TestJobHistoryParsing  extends TestCase {
                                           Keys.TRACKER_NAME, 
                                           Keys.JOBNAME, 
                                           Keys.JOBCONF,
-                                          Keys.USER},
-                   new String[] {value1, value2, value3, value4, value5});
+                                          Keys.USER,
+                                          Keys.SPLITS},
+                   new String[] {value1, value2, value3, value4, value5,
+                                 value6});
     // close history file
     out.close();
     historyWriter.remove(out);
@@ -99,5 +109,6 @@ public class TestJobHistoryParsing  extends TestCase {
     assertEquals(value3, job.get(Keys.JOBNAME));
     assertEquals(value4, job.get(Keys.JOBCONF));
     assertEquals(value5, job.get(Keys.USER));
+    assertEquals(value6, job.get(Keys.SPLITS));
   }
 }