lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [03/18] lucene-solr:jira/solr-11702: LUCENE-8110: Fix potential IndexOutOfBoundsException in *Classifier.getClasses(?, int).
Date Wed, 03 Jan 2018 10:51:51 GMT
LUCENE-8110: Fix potential IndexOutOfBoundsException in *Classifier.getClasses(?,int).


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/af41d02e
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/af41d02e
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/af41d02e

Branch: refs/heads/jira/solr-11702
Commit: af41d02eae6a58fd450553f9a09c9325ddf6e0ab
Parents: 05ab5e1
Author: Christine Poerschke <cpoerschke@apache.org>
Authored: Thu Dec 28 12:28:41 2017 +0000
Committer: Christine Poerschke <cpoerschke@apache.org>
Committed: Thu Dec 28 12:28:41 2017 +0000

----------------------------------------------------------------------
 lucene/CHANGES.txt                                                | 3 +++
 .../java/org/apache/lucene/classification/BM25NBClassifier.java   | 1 +
 .../org/apache/lucene/classification/KNearestFuzzyClassifier.java | 1 +
 .../apache/lucene/classification/KNearestNeighborClassifier.java  | 1 +
 .../apache/lucene/classification/SimpleNaiveBayesClassifier.java  | 1 +
 .../document/SimpleNaiveBayesDocumentClassifier.java              | 1 +
 6 files changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/af41d02e/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 0da2cfe..84ba235 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -104,6 +104,9 @@ Bug Fixes
 * LUCENE-8077: Fixed bug in how CheckIndex verifies doc-value iterators.
   (Xiaoshan Sun via Adrien Grand)
 
+* LUCENE-8110: Fix potential IndexOutOfBoundsException in *Classifier.getClasses(?,int).
+  (Christine Poerschke)
+
 ======================= Lucene 7.2.0 =======================
 
 API Changes

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/af41d02e/lucene/classification/src/java/org/apache/lucene/classification/BM25NBClassifier.java
----------------------------------------------------------------------
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/BM25NBClassifier.java
b/lucene/classification/src/java/org/apache/lucene/classification/BM25NBClassifier.java
index 1a74416..39a5b2f 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/BM25NBClassifier.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/BM25NBClassifier.java
@@ -124,6 +124,7 @@ public class BM25NBClassifier implements Classifier<BytesRef> {
   public List<ClassificationResult<BytesRef>> getClasses(String text, int max)
throws IOException {
     List<ClassificationResult<BytesRef>> assignedClasses = assignClassNormalizedList(text);
     Collections.sort(assignedClasses);
+    max = Math.min(max, assignedClasses.size());
     return assignedClasses.subList(0, max);
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/af41d02e/lucene/classification/src/java/org/apache/lucene/classification/KNearestFuzzyClassifier.java
----------------------------------------------------------------------
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/KNearestFuzzyClassifier.java
b/lucene/classification/src/java/org/apache/lucene/classification/KNearestFuzzyClassifier.java
index cbd241b..65effe4 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/KNearestFuzzyClassifier.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/KNearestFuzzyClassifier.java
@@ -140,6 +140,7 @@ public class KNearestFuzzyClassifier implements Classifier<BytesRef>
{
     TopDocs knnResults = knnSearch(text);
     List<ClassificationResult<BytesRef>> assignedClasses = buildListFromTopDocs(knnResults);
     Collections.sort(assignedClasses);
+    max = Math.min(max, assignedClasses.size());
     return assignedClasses.subList(0, max);
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/af41d02e/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
----------------------------------------------------------------------
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
b/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
index f0391f4..f145912 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
@@ -162,6 +162,7 @@ public class KNearestNeighborClassifier implements Classifier<BytesRef>
{
     TopDocs knnResults = knnSearch(text);
     List<ClassificationResult<BytesRef>> assignedClasses = buildListFromTopDocs(knnResults);
     Collections.sort(assignedClasses);
+    max = Math.min(max, assignedClasses.size());
     return assignedClasses.subList(0, max);
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/af41d02e/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
----------------------------------------------------------------------
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
b/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
index 3509df5..3bb701f 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
@@ -132,6 +132,7 @@ public class SimpleNaiveBayesClassifier implements Classifier<BytesRef>
{
   public List<ClassificationResult<BytesRef>> getClasses(String text, int max)
throws IOException {
     List<ClassificationResult<BytesRef>> assignedClasses = assignClassNormalizedList(text);
     Collections.sort(assignedClasses);
+    max = Math.min(max, assignedClasses.size());
     return assignedClasses.subList(0, max);
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/af41d02e/lucene/classification/src/java/org/apache/lucene/classification/document/SimpleNaiveBayesDocumentClassifier.java
----------------------------------------------------------------------
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/document/SimpleNaiveBayesDocumentClassifier.java
b/lucene/classification/src/java/org/apache/lucene/classification/document/SimpleNaiveBayesDocumentClassifier.java
index 6bc8573..097fe0c 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/document/SimpleNaiveBayesDocumentClassifier.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/document/SimpleNaiveBayesDocumentClassifier.java
@@ -105,6 +105,7 @@ public class SimpleNaiveBayesDocumentClassifier extends SimpleNaiveBayesClassifi
   public List<ClassificationResult<BytesRef>> getClasses(Document document, int
max) throws IOException {
     List<ClassificationResult<BytesRef>> assignedClasses = assignNormClasses(document);
     Collections.sort(assignedClasses);
+    max = Math.min(max, assignedClasses.size());
     return assignedClasses.subList(0, max);
   }
 


Mime
View raw message