Skip to content

Apache Lucene open-source search software

LUCENE-9832: Hunspell: SIOOBE in GeneratingSuggester.expandRoot (#12)

Peter Gromovefa88a1790fa
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
index 68af022011a..1770b03ca08 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java
@@ -267,6 +267,7 @@ class GeneratingSuggester {
}
private boolean checkAffixCondition(int suffixId, char[] word, int offset, int length) {
+ if (length < 0) return false;
int condition = dictionary.getAffixCondition(suffixId);
return condition == 0 || dictionary.patterns.get(condition).acceptsStem(word, offset, length);
}
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestSpellChecking.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestSpellChecking.java
index c1312370a74..7e175b6b922 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestSpellChecking.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestSpellChecking.java
@@ -225,6 +225,10 @@ public class TestSpellChecking extends LuceneTestCase {
doTest("keyDefault");
}
+ public void testDoNotFailWhenExpandingRootWithLongerStrippingAffix() throws Exception {
+ doTest("longStrip");
+ }
+
protected void doTest(String name) throws Exception {
checkSpellCheckerExpectations(
Path.of(getClass().getResource(name + ".aff").toURI()).getParent().resolve(name));
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.aff
new file mode 100644
index 00000000000..21b454e1e91
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.aff
@@ -0,0 +1,2 @@
+SFX A N 1
+SFX A veryLongStrip x .
\ No newline at end of file
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.dic b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.dic
new file mode 100644
index 00000000000..91a4176ec2c
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.dic
@@ -0,0 +1,2 @@
+1
+foo/A
\ No newline at end of file
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.sug b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.sug
new file mode 100644
index 00000000000..19102815663
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.sug
@@ -0,0 +1 @@
+foo
\ No newline at end of file
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.wrong b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.wrong
new file mode 100644
index 00000000000..bedaad5bd5d
--- /dev/null
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/longStrip.wrong
@@ -0,0 +1 @@
+foox
\ No newline at end of file