diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 62c0c0f5ab8..e486cdd0164 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -124,6 +124,11 @@ Bug Fixes * LUCENE-6918: LRUQueryCache.onDocIdSetEviction is only called when at least one DocIdSet is being evicted. (Adrien Grand) +* LUCENE-6910: fix 'if ... > Integer.MAX_VALUE' check in + (Binary|Numeric)DocValuesFieldUpdates.merge + (https://scan.coverity.com/projects/5620 CID 119973 and CID 120081) + (Christine Poerschke, Coverity Scan (via Rishabh Patel)) + ======================= Lucene 5.4.0 ======================= New Features diff --git a/lucene/core/src/java/org/apache/lucene/index/BinaryDocValuesFieldUpdates.java b/lucene/core/src/java/org/apache/lucene/index/BinaryDocValuesFieldUpdates.java index a5b817f0509..684afefbbbc 100644 --- a/lucene/core/src/java/org/apache/lucene/index/BinaryDocValuesFieldUpdates.java +++ b/lucene/core/src/java/org/apache/lucene/index/BinaryDocValuesFieldUpdates.java @@ -169,12 +169,12 @@ class BinaryDocValuesFieldUpdates extends DocValuesFieldUpdates { @Override public void merge(DocValuesFieldUpdates other) { BinaryDocValuesFieldUpdates otherUpdates = (BinaryDocValuesFieldUpdates) other; - int newSize = size + otherUpdates.size; - if (newSize > Integer.MAX_VALUE) { + if (otherUpdates.size > Integer.MAX_VALUE - size) { throw new IllegalStateException( "cannot support more than Integer.MAX_VALUE doc/value entries; size=" + size + " other.size=" + otherUpdates.size); } + final int newSize = size + otherUpdates.size; docs = docs.grow(newSize); offsets = offsets.grow(newSize); lengths = lengths.grow(newSize); diff --git a/lucene/core/src/java/org/apache/lucene/index/NumericDocValuesFieldUpdates.java b/lucene/core/src/java/org/apache/lucene/index/NumericDocValuesFieldUpdates.java index dd6e8599317..641c594d388 100644 --- a/lucene/core/src/java/org/apache/lucene/index/NumericDocValuesFieldUpdates.java +++ b/lucene/core/src/java/org/apache/lucene/index/NumericDocValuesFieldUpdates.java @@ -144,7 +144,7 @@ class NumericDocValuesFieldUpdates extends DocValuesFieldUpdates { public void merge(DocValuesFieldUpdates other) { assert other instanceof NumericDocValuesFieldUpdates; NumericDocValuesFieldUpdates otherUpdates = (NumericDocValuesFieldUpdates) other; - if (size + otherUpdates.size > Integer.MAX_VALUE) { + if (otherUpdates.size > Integer.MAX_VALUE - size) { throw new IllegalStateException( "cannot support more than Integer.MAX_VALUE doc/value entries; size=" + size + " other.size=" + otherUpdates.size);