DCausse has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/285380

Change subject: Fix security violations
......................................................................

Fix security violations

Plugins are now loaded in their own ClassLoader. It is no more possible to use
the package trick to access package visibles members/methods owned by
elasticsearch/lucene.  This patch removes all org.elasticsearch and
org.apache.lucene packages.  Unfortunately this was not seen by integration
tests because we use the same classloader.

Bug: T133618
Change-Id: I16c09ec2ca03555e3c13814fd86fb1506ca95657
---
R 
src/main/java/org/wikimedia/search/extra/regex/ContainsCharacterRunAutomaton.java
D src/main/java/org/wikimedia/search/extra/regex/RegexTooComplexException.java
M src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java
3 files changed, 10 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/search/extra 
refs/changes/80/285380/1

diff --git 
a/src/main/java/org/apache/lucene/util/automaton/ContainsCharacterRunAutomaton.java
 
b/src/main/java/org/wikimedia/search/extra/regex/ContainsCharacterRunAutomaton.java
similarity index 92%
rename from 
src/main/java/org/apache/lucene/util/automaton/ContainsCharacterRunAutomaton.java
rename to 
src/main/java/org/wikimedia/search/extra/regex/ContainsCharacterRunAutomaton.java
index ff4182e..9a8f9a1 100644
--- 
a/src/main/java/org/apache/lucene/util/automaton/ContainsCharacterRunAutomaton.java
+++ 
b/src/main/java/org/wikimedia/search/extra/regex/ContainsCharacterRunAutomaton.java
@@ -1,6 +1,9 @@
-package org.apache.lucene.util.automaton;
+package org.wikimedia.search.extra.regex;
 
-public class ContainsCharacterRunAutomaton extends RunAutomaton {
+import org.apache.lucene.util.automaton.Automaton;
+import org.apache.lucene.util.automaton.RunAutomaton;
+
+class ContainsCharacterRunAutomaton extends RunAutomaton {
     public ContainsCharacterRunAutomaton(Automaton a) {
         super(a, Character.MAX_CODE_POINT, true);
     }
@@ -13,6 +16,8 @@
     public boolean contains(String s) {
         int end = s.length();
         int offset = 0;
+        // super.initial is final
+        final int initial = getInitialState();
         while (offset < end) {
             int cp = s.codePointAt(offset);
             offset += Character.charCount(cp);
@@ -20,7 +25,7 @@
             if (p == -1) {
                 continue;
             }
-            if (accept[p]) {
+            if (isAccept(p)) {
                 return true;
             }
             /*
@@ -36,7 +41,7 @@
                 if (p == -1) {
                     break;
                 }
-                if (accept[p]) {
+                if (isAccept(p)) {
                     return true;
                 }
             }
diff --git 
a/src/main/java/org/wikimedia/search/extra/regex/RegexTooComplexException.java 
b/src/main/java/org/wikimedia/search/extra/regex/RegexTooComplexException.java
deleted file mode 100644
index 3161bb9..0000000
--- 
a/src/main/java/org/wikimedia/search/extra/regex/RegexTooComplexException.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package org.wikimedia.search.extra.regex;
-
-import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
-
-/**
- * Wraps Lucene's XTooComplexToDeterminizeException to be serializable to be
- * thrown over the wire.
- */
-public class RegexTooComplexException extends RuntimeException {
-    private static final long serialVersionUID = -41975279199116247L;
-
-    public RegexTooComplexException(TooComplexToDeterminizeException e) {
-        super(e.getMessage());
-    }
-}
diff --git 
a/src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java 
b/src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java
index bcb9e9d..1eac220 100644
--- a/src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java
+++ b/src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java
@@ -10,11 +10,7 @@
 import org.apache.lucene.search.TwoPhaseIterator;
 import org.apache.lucene.util.automaton.Automaton;
 import org.apache.lucene.util.automaton.CharacterRunAutomaton;
-import org.apache.lucene.util.automaton.ContainsCharacterRunAutomaton;
 import org.apache.lucene.util.automaton.RegExp;
-import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
-import org.elasticsearch.common.logging.ESLogger;
-import org.elasticsearch.common.logging.ESLoggerFactory;
 import org.elasticsearch.common.lucene.search.Queries;
 import org.wikimedia.search.extra.regex.expression.Expression;
 import org.wikimedia.search.extra.regex.ngram.AutomatonTooComplexException;
@@ -23,7 +19,6 @@
 
 @EqualsAndHashCode
 public class SourceRegexQuery extends Query {
-    private static final ESLogger log = 
ESLoggerFactory.getLogger(SourceRegexQuery.class.getPackage().getName());
     private final String fieldPath;
     private final String ngramFieldPath;
     private final String regex;
@@ -87,18 +82,7 @@
     }
 
     private static Automaton regexToAutomaton(RegExp regex, int 
maxDeterminizedStates) {
-        try {
-            return regex.toAutomaton(maxDeterminizedStates);
-        } catch (TooComplexToDeterminizeException e) {
-            /*
-             * Since we're going to lose the stack trace we give our future
-             * selves an opportunity to log it in case we need it.
-             */
-            if (log.isDebugEnabled()) {
-                log.debug("Regex too complex to determinize", e);
-            }
-            throw new RegexTooComplexException(e);
-        }
+        return regex.toAutomaton(maxDeterminizedStates);
     }
 
     /**

-- 
To view, visit https://gerrit.wikimedia.org/r/285380
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I16c09ec2ca03555e3c13814fd86fb1506ca95657
Gerrit-PatchSet: 1
Gerrit-Project: search/extra
Gerrit-Branch: master
Gerrit-Owner: DCausse <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to