You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2022/09/13 12:47:36 UTC

[lucene] 02/02: Fix integer overflow in tests.

This is an automated email from the ASF dual-hosted git repository.

jpountz pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit fe52405791ec44131fced3d5a2f927ec7d735994
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Tue Sep 13 14:30:39 2022 +0200

    Fix integer overflow in tests.
---
 .../org/apache/lucene/backward_codecs/lucene80/TestIndexedDISI.java  | 5 +++--
 .../src/test/org/apache/lucene/codecs/lucene90/TestIndexedDISI.java  | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestIndexedDISI.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestIndexedDISI.java
index 5d44d760d38..2ab647c7db1 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestIndexedDISI.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestIndexedDISI.java
@@ -474,8 +474,9 @@ public class TestIndexedDISI extends LuceneTestCase {
   private void doTestRandom(Directory dir) throws IOException {
     Random random = random();
     final int maxStep = TestUtil.nextInt(random, 1, 1 << TestUtil.nextInt(random, 2, 20));
-    final int numDocs = TestUtil.nextInt(random, 1, Math.min(100000, Integer.MAX_VALUE / maxStep));
-    BitSet docs = new SparseFixedBitSet(numDocs * (maxStep + 1));
+    final int numDocs =
+        TestUtil.nextInt(random, 1, Math.min(100000, (Integer.MAX_VALUE - 1) / maxStep));
+    BitSet docs = new SparseFixedBitSet(numDocs * maxStep + 1);
     int lastDoc = -1;
     for (int doc = -1, i = 0; i < numDocs; ++i) {
       doc += TestUtil.nextInt(random, 1, maxStep);
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestIndexedDISI.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestIndexedDISI.java
index a45f0e6d5ac..3ba3db81565 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestIndexedDISI.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestIndexedDISI.java
@@ -473,8 +473,9 @@ public class TestIndexedDISI extends LuceneTestCase {
   private void doTestRandom(Directory dir) throws IOException {
     Random random = random();
     final int maxStep = TestUtil.nextInt(random, 1, 1 << TestUtil.nextInt(random, 2, 20));
-    final int numDocs = TestUtil.nextInt(random, 1, Math.min(100000, Integer.MAX_VALUE / maxStep));
-    BitSet docs = new SparseFixedBitSet(numDocs * (maxStep + 1));
+    final int numDocs =
+        TestUtil.nextInt(random, 1, Math.min(100000, (Integer.MAX_VALUE - 1) / maxStep));
+    BitSet docs = new SparseFixedBitSet(numDocs * maxStep + 1);
     int lastDoc = -1;
     for (int doc = -1, i = 0; i < numDocs; ++i) {
       doc += TestUtil.nextInt(random, 1, maxStep);