You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2022/06/22 20:23:42 UTC
[lucene] branch main updated: LUCENE-10607: Fix potential integer overflow in maxArcs computions (#970)
This is an automated email from the ASF dual-hosted git repository.
dweiss pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new 2da9951f23a LUCENE-10607: Fix potential integer overflow in maxArcs computions (#970)
2da9951f23a is described below
commit 2da9951f23afa2da52eaee9b691ca5f894a93c27
Author: tang donghai <ta...@gmail.com>
AuthorDate: Thu Jun 23 04:23:36 2022 +0800
LUCENE-10607: Fix potential integer overflow in maxArcs computions (#970)
---
lucene/CHANGES.txt | 2 ++
.../lucene/search/suggest/document/NRTSuggesterBuilder.java | 8 ++++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 66d0924a870..c28539cbdd6 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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
---------------------
diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/NRTSuggesterBuilder.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/NRTSuggesterBuilder.java
index 9123ab75528..3a8c2ed77a0 100644
--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/NRTSuggesterBuilder.java
+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/NRTSuggesterBuilder.java
@@ -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> {