From f9c26ed5017974493dfbafae470b5315a40f0dd0 Mon Sep 17 00:00:00 2001 From: Benjamin Trent Date: Tue, 8 Nov 2022 09:55:07 -0500 Subject: [PATCH] Fix latent casting bug in BKDWriter (#11907) --- lucene/CHANGES.txt | 2 ++ .../core/src/java/org/apache/lucene/util/bkd/BKDWriter.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index aba34b0fc9e..bb0bb3539bc 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -137,6 +137,8 @@ Bug Fixes * GITHUB#11807: Don't rewrite queries in unified highlighter. (Alan Woodward) +* GITHUB#11907: Fix latent casting bugs in BKDWriter. (Ben Trent) + Optimizations --------------------- * GITHUB#11738: Optimize MultiTermQueryConstantScoreWrapper when a term is present that matches all diff --git a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java index efd2e0522d5..9f1fa537884 100644 --- a/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java +++ b/lucene/core/src/java/org/apache/lucene/util/bkd/BKDWriter.java @@ -515,7 +515,7 @@ public class BKDWriter implements Closeable { checkMaxLeafNodeCount(numLeaves); - final byte[] splitPackedValues = new byte[numSplits * config.bytesPerDim]; + final byte[] splitPackedValues = new byte[Math.multiplyExact(numSplits, config.bytesPerDim)]; final byte[] splitDimensionValues = new byte[numSplits]; final long[] leafBlockFPs = new long[numLeaves]; @@ -946,7 +946,7 @@ public class BKDWriter implements Closeable { // Indexed by nodeID, but first (root) nodeID is 1. We do 1+ because the lead byte at each // recursion says which dim we split on. - byte[] splitPackedValues = new byte[Math.toIntExact(numSplits * config.bytesPerDim)]; + byte[] splitPackedValues = new byte[Math.multiplyExact(numSplits, config.bytesPerDim)]; byte[] splitDimensionValues = new byte[numSplits]; // +1 because leaf count is power of 2 (e.g. 8), and innerNodeCount is power of 2 minus 1 (e.g.