Skip to content

Commit f7d54b8

Browse files
committed
Port commit 9d10d6f92cc for LUCENE-5660 in Lucene 4.8.1
1 parent de4d8fb commit f7d54b8

3 files changed

Lines changed: 25 additions & 21 deletions

File tree

src/Lucene.Net.Suggest/Suggest/Analyzing/AnalyzingSuggester.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,8 @@ internal ISet<Int32sRef> ToFiniteStrings(BytesRef surfaceForm, TokenStreamToAuto
979979
ReplaceSep(automaton);
980980
automaton = ConvertAutomaton(automaton);
981981

982-
if (Debugging.AssertsEnabled) Debugging.Assert(SpecialOperations.IsFinite(automaton));
982+
// TODO: LUCENE-5660 re-enable this once we disallow massive suggestion strings
983+
// if (Debugging.AssertsEnabled) Debugging.Assert(SpecialOperations.IsFinite(automaton));
983984

984985
// Get all paths from the automaton (there can be
985986
// more than one path, eg if the analyzer created a

src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,24 +1499,24 @@ internal static IEnumerable<Input> Shuffle(params Input[] values)
14991499
return asList;
15001500
}
15011501

1502-
// LUCENENET TODO: This is a test from Lucene 4.8.1 that currently produces a stack overflow
1503-
//// TODO: we need BaseSuggesterTestCase?
1504-
//[Test]
1505-
//public void TestTooLongSuggestion()
1506-
//{
1507-
// Analyzer a = new MockAnalyzer(Random);
1508-
// AnalyzingSuggester suggester = new AnalyzingSuggester(a);
1509-
// String bigString = TestUtil.RandomSimpleString(Random, 60000, 60000);
1510-
// try
1511-
// {
1512-
// suggester.Build(new InputArrayEnumerator(new Input[] {
1513-
// new Input(bigString, 7)}));
1514-
// fail("did not hit expected exception");
1515-
// }
1516-
// catch (Exception iae) when (iae.IsIllegalArgumentException())
1517-
// {
1518-
// // expected
1519-
// }
1520-
//}
1502+
// TODO: we need BaseSuggesterTestCase?
1503+
[Test]
1504+
public void TestTooLongSuggestion()
1505+
{
1506+
Analyzer a = new MockAnalyzer(Random);
1507+
AnalyzingSuggester suggester = new AnalyzingSuggester(a);
1508+
string bigString = TestUtil.RandomSimpleString(Random, 60000, 60000);
1509+
try
1510+
{
1511+
suggester.Build(new InputArrayEnumerator([
1512+
new Input(bigString, 7)
1513+
]));
1514+
Assert.Fail("did not hit expected exception");
1515+
}
1516+
catch (ArgumentOutOfRangeException /*iae*/) // LUCENENET-specific AOORE for .NET semantics
1517+
{
1518+
// expected
1519+
}
1520+
}
15211521
}
15221522
}

src/Lucene.Net/Util/OfflineSorter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ public virtual void Write(byte[] bytes)
670670
/// by the bytes.
671671
/// </summary>
672672
/// <exception cref="ArgumentNullException"><paramref name="bytes"/> is <c>null</c>.</exception>
673-
/// <exception cref="ArgumentOutOfRangeException"><paramref name="off"/> or <paramref name="len"/> is less than 0.</exception>
673+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="off"/> or <paramref name="len"/> is less than 0, or <paramref name="len"/> is greater than <see cref="short.MaxValue"/>.</exception>
674674
/// <exception cref="ArgumentException"><paramref name="off"/> and <paramref name="len"/> refer to a position outside of the array.</exception>
675675
public virtual void Write(byte[] bytes, int off, int len)
676676
{
@@ -683,6 +683,9 @@ public virtual void Write(byte[] bytes, int off, int len)
683683
if (off > bytes.Length - len) // Checks for int overflow
684684
throw new ArgumentException("Index and length must refer to a location within the array.");
685685

686+
if (len > short.MaxValue)
687+
throw new ArgumentOutOfRangeException(nameof(len), $"len must be <= {short.MaxValue}; got {len}");
688+
686689
os.Write((short)len);
687690
os.Write(bytes, off, len);
688691
}

0 commit comments

Comments
 (0)