LUCENE-10607: Fix potential integer overflow in maxArcs computions (#970)

This commit is contained in:
tang donghai 2022-06-23 04:23:36 +08:00 committed by GitHub
parent bc72a53efc
commit 2da9951f23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -122,6 +122,8 @@ Bug Fixes
* LUCENE-10611: Fix failure when KnnVectorQuery has very selective filter (Kaival Parikh)
* LUCENE-10607: Fix potential integer overflow in maxArcs computions (Tang Donghai)
Other
---------------------

View File

@ -124,11 +124,15 @@ final class NRTSuggesterBuilder {
* <p>TODO: is there a better way to make the fst built to be more TopNSearcher friendly?
*/
private static int maxNumArcsForDedupByte(int currentNumDedupBytes) {
int maxArcs = 1 + (2 * currentNumDedupBytes);
long maxArcs = 2 * (long) currentNumDedupBytes + 1;
// return immediately when maxArcs is greater than 255 to prevent integer overflow
if (maxArcs >= 255) {
return 255;
}
if (currentNumDedupBytes > 5) {
maxArcs *= currentNumDedupBytes;
}
return Math.min(maxArcs, 255);
return (int) Math.min(maxArcs, 255);
}
private static final class Entry implements Comparable<Entry> {