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/14 07:09:53 UTC

[lucene] branch main updated: Fix integer overflow in tests.

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

jpountz 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 a426c6fec39 Fix integer overflow in tests.
a426c6fec39 is described below

commit a426c6fec39641c591f9bb3bb3396ba412b55c30
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 b15d2cfa836..800c31d5e5d 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
@@ -476,8 +476,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);