From 6e78f379d927271b3e649921388e8dba32c83587 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 6 Nov 2024 11:34:27 +0100 Subject: [PATCH] Fix TestPostingsUtil#testIntegerOverflow failure. (#13979) The group vint logic is mistakenly using the long->int conversion logic for the case when integers are being written rather than longs. Closes #13978 --- .../src/java/org/apache/lucene/util/GroupVIntUtil.java | 2 +- .../lucene/codecs/lucene101/TestPostingsUtil.java | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/GroupVIntUtil.java b/lucene/core/src/java/org/apache/lucene/util/GroupVIntUtil.java index 949292fd9d2..e95e2eee4db 100644 --- a/lucene/core/src/java/org/apache/lucene/util/GroupVIntUtil.java +++ b/lucene/core/src/java/org/apache/lucene/util/GroupVIntUtil.java @@ -292,7 +292,7 @@ public final class GroupVIntUtil { // tail vints for (; readPos < limit; readPos++) { - out.writeVInt(toInt(values[readPos])); + out.writeVInt(values[readPos]); } } } diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene101/TestPostingsUtil.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene101/TestPostingsUtil.java index 41bb5c01f07..5d02d0561e3 100644 --- a/lucene/core/src/test/org/apache/lucene/codecs/lucene101/TestPostingsUtil.java +++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene101/TestPostingsUtil.java @@ -27,7 +27,15 @@ public class TestPostingsUtil extends LuceneTestCase { // checks for bug described in https://github.com/apache/lucene/issues/13373 public void testIntegerOverflow() throws IOException { - final int size = random().nextInt(1, ForUtil.BLOCK_SIZE); + // Size that writes the first value as a regular vint + int randomSize1 = random().nextInt(1, 3); + // Size that writes the first value as a group vint + int randomSize2 = random().nextInt(4, ForUtil.BLOCK_SIZE); + doTestIntegerOverflow(randomSize1); + doTestIntegerOverflow(randomSize2); + } + + private void doTestIntegerOverflow(int size) throws IOException { final int[] docDeltaBuffer = new int[size]; final int[] freqBuffer = new int[size];