Skip to content

Commit 4c02f10

Browse files
Aggregation Array OOB Error (#20204)
Co-authored-by: Sandesh Kumar <[email protected]>
1 parent 659942a commit 4c02f10

File tree

4 files changed

+76
-14
lines changed

4 files changed

+76
-14
lines changed

client/rest-high-level/src/test/java/org/opensearch/client/SearchIT.java

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
import org.opensearch.search.aggregations.bucket.composite.CompositeAggregation;
8585
import org.opensearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder;
8686
import org.opensearch.search.aggregations.bucket.composite.TermsValuesSourceBuilder;
87+
import org.opensearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder;
88+
import org.opensearch.search.aggregations.bucket.histogram.DateHistogramInterval;
89+
import org.opensearch.search.aggregations.bucket.histogram.ParsedDateHistogram;
8790
import org.opensearch.search.aggregations.bucket.range.Range;
8891
import org.opensearch.search.aggregations.bucket.range.RangeAggregationBuilder;
8992
import org.opensearch.search.aggregations.bucket.terms.MultiTermsAggregationBuilder;
@@ -237,6 +240,32 @@ public void indexDocuments() throws IOException {
237240
client().performRequest(createFilteredAlias);
238241
}
239242

243+
{
244+
Request create = new Request(HttpPut.METHOD_NAME, "/index5");
245+
create.setJsonEntity(
246+
"{"
247+
+ " \"mappings\": {"
248+
+ " \"properties\": {"
249+
+ " \"date_created\": {"
250+
+ " \"type\": \"date\""
251+
+ " },"
252+
+ " \"distribution\": {"
253+
+ " \"properties\": {"
254+
+ " \"number_events\": {"
255+
+ " \"type\": \"unsigned_long\""
256+
+ " }"
257+
+ " }"
258+
+ " }"
259+
+ " }"
260+
+ " }"
261+
+ "}"
262+
);
263+
client().performRequest(create);
264+
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index5/_doc/1");
265+
doc1.setJsonEntity("{\"date_created\":\"2024\", \"distribution\":{\"number_events\": 1000000}}");
266+
client().performRequest(doc1);
267+
}
268+
240269
client().performRequest(new Request(HttpPost.METHOD_NAME, "/_refresh"));
241270
}
242271

@@ -514,6 +543,38 @@ public void testSearchWithTermsAndRangeAgg() throws IOException {
514543
}
515544
}
516545

546+
public void testSearchWithDateAndRangeAgg() throws IOException {
547+
SearchRequest searchRequest = new SearchRequest("index5");
548+
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
549+
DateHistogramAggregationBuilder yearAgg = new DateHistogramAggregationBuilder("year").field("date_created")
550+
.calendarInterval(DateHistogramInterval.YEAR)
551+
.format("yyyy");
552+
553+
RangeAggregationBuilder rangeAgg = new RangeAggregationBuilder("number_events").field("distribution.number_events")
554+
.addRange("0--999", 0.0, 1000.0)
555+
.addRange("999--", 1000.0, 10_000_000_000_00L);
556+
searchSourceBuilder.aggregation(yearAgg).aggregation(rangeAgg);
557+
searchSourceBuilder.size(0);
558+
searchRequest.source(searchSourceBuilder);
559+
SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync);
560+
assertSearchHeader(searchResponse);
561+
ParsedDateHistogram yearHistogram = searchResponse.getAggregations().get("year");
562+
assertEquals(1, yearHistogram.getBuckets().size());
563+
assertEquals("2024", yearHistogram.getBuckets().get(0).getKeyAsString());
564+
Range rangeAggregation = searchResponse.getAggregations().get("number_events");
565+
assertEquals(2, rangeAggregation.getBuckets().size());
566+
{
567+
Range.Bucket bucket = rangeAggregation.getBuckets().get(0);
568+
assertEquals("0--999", bucket.getKeyAsString());
569+
assertEquals(0, bucket.getDocCount());
570+
}
571+
{
572+
Range.Bucket bucket = rangeAggregation.getBuckets().get(1);
573+
assertEquals("999--", bucket.getKeyAsString());
574+
assertEquals(1, bucket.getDocCount());
575+
}
576+
}
577+
517578
public void testSearchWithTermsAndWeightedAvg() throws IOException {
518579
SearchRequest searchRequest = new SearchRequest("index");
519580
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
@@ -1786,7 +1847,7 @@ public void testCountAllIndicesNoQuery() throws IOException {
17861847
CountRequest countRequest = new CountRequest();
17871848
CountResponse countResponse = execute(countRequest, highLevelClient()::count, highLevelClient()::countAsync);
17881849
assertCountHeader(countResponse);
1789-
assertEquals(12, countResponse.getCount());
1850+
assertEquals(13, countResponse.getCount());
17901851
}
17911852

17921853
public void testCountOneIndexMatchQuery() throws IOException {

release-notes/opensearch.release-notes-3.4.0.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ Compatible with OpenSearch and OpenSearch Dashboards version 3.4.0
66
- Allow setting index.creation_date on index creation and restore for plugin compatibility and migrations ([#19931](https://github.com/opensearch-project/OpenSearch/pull/19931))
77
- Add support for a ForkJoinPool type ([#19008](https://github.com/opensearch-project/OpenSearch/pull/19008))
88
- Add seperate shard limit validation for local and remote indices ([#19532](https://github.com/opensearch-project/OpenSearch/pull/19532))
9-
- Use Lucene `pack` method for `half_float` and `usigned_long` when using `ApproximatePointRangeQuery`.
9+
- Use Lucene `pack` method for `half_float` and `unsigned_long` when using `ApproximatePointRangeQuery` ([#19553](https://github.com/opensearch-project/OpenSearch/pull/19553))
1010
- New cluster setting search.query.max_query_string_length_monitor_only ([#19539](https://github.com/opensearch-project/OpenSearch/pull/19539))
1111
- Add a mapper for context aware segments grouping criteria ([#19233](https://github.com/opensearch-project/OpenSearch/pull/19233))
1212
- Return full error for GRPC error response ([#19568](https://github.com/opensearch-project/OpenSearch/pull/19568))
13-
- Add support for repository with Server side encryption enabled and client side encryption as well based on a flag. ([#19630)](https://github.com/opensearch-project/OpenSearch/pull/19630))
13+
- Add support for repository with Server side encryption enabled and client side encryption as well based on a flag ([#19630](https://github.com/opensearch-project/OpenSearch/pull/19630))
1414
- Add pluggable gRPC interceptors with explicit ordering([#19005](https://github.com/opensearch-project/OpenSearch/pull/19005))
1515
- Add BindableServices extension point to transport-grpc-spi ([#19304](https://github.com/opensearch-project/OpenSearch/pull/19304))
1616
- Add metrics for the merged segment warmer feature ([#18929](https://github.com/opensearch-project/OpenSearch/pull/18929))
@@ -19,7 +19,7 @@ Compatible with OpenSearch and OpenSearch Dashboards version 3.4.0
1919
- Allow collectors take advantage of preaggregated data using collectRange API ([#20009](https://github.com/opensearch-project/OpenSearch/pull/20009))
2020
- Bulk collection logic for metrics and cardinality aggregations ([#20067](https://github.com/opensearch-project/OpenSearch/pull/20067))
2121
- Add pointer based lag metric in pull-based ingestion ([#19635](https://github.com/opensearch-project/OpenSearch/pull/19635))
22-
- Introduced internal API for retrieving metadata about requested indices from transport actions ([#18523](https://github.com/opensearch-project/OpenSearch/pull/18523))
22+
- Introduced internal API for retrieving metadata about requested indices from transport actions ([#18523](https://github.com/opensearch-project/OpenSearch/pull/18523))
2323
- Add cluster defaults for merge autoThrottle, maxMergeThreads, and maxMergeCount; Add segment size filter to the merged segment warmer ([#19629](https://github.com/opensearch-project/OpenSearch/pull/19629))
2424
- Add build-tooling to run in FIPS environment ([#18921](https://github.com/opensearch-project/OpenSearch/pull/18921))
2525
- Add SMILE/CBOR/YAML document format support to Bulk GRPC endpoint ([#19744](https://github.com/opensearch-project/OpenSearch/pull/19744))
@@ -83,9 +83,9 @@ Compatible with OpenSearch and OpenSearch Dashboards version 3.4.0
8383
- Fix pull-based ingestion out-of-bounds offset scenarios and remove persisted offsets ([#19607](https://github.com/opensearch-project/OpenSearch/pull/19607))
8484
- Fix issue with updating core with a patch number other than 0 ([#19377](https://github.com/opensearch-project/OpenSearch/pull/19377))
8585
- [Java Agent] Allow JRT protocol URLs in protection domain extraction ([#19683](https://github.com/opensearch-project/OpenSearch/pull/19683))
86-
- Fix potential concurrent modification exception when updating allocation filters ([#19701])(https://github.com/opensearch-project/OpenSearch/pull/19701))
86+
- Fix potential concurrent modification exception when updating allocation filters ([#19701](https://github.com/opensearch-project/OpenSearch/pull/19701))
8787
- Fix wildcard query with escaped backslash followed by wildcard character ([#19719](https://github.com/opensearch-project/OpenSearch/pull/19719))
88-
- Fix file-based ingestion consumer to handle start point beyond max line number([#19757])(https://github.com/opensearch-project/OpenSearch/pull/19757))
88+
- Fix file-based ingestion consumer to handle start point beyond max line number ([#19757](https://github.com/opensearch-project/OpenSearch/pull/19757))
8989
- Fix IndexOutOfBoundsException when running include/exclude on non-existent prefix in terms aggregations ([#19637](https://github.com/opensearch-project/OpenSearch/pull/19637))
9090
- Fixed assertion unsafe use of ClusterService.state() in ResourceUsageCollectorService ([#19775])(https://github.com/opensearch-project/OpenSearch/pull/19775))
9191
- Fix Unified highlighter for nested fields when using matchPhrasePrefixQuery ([#19442](https://github.com/opensearch-project/OpenSearch/pull/19442))
@@ -101,7 +101,8 @@ Compatible with OpenSearch and OpenSearch Dashboards version 3.4.0
101101
- Fix toBuilder method in EngineConfig to include mergedSegmentTransferTracker([#20105](https://github.com/opensearch-project/OpenSearch/pull/20105))
102102
- Fixed handling of property index in BulkRequest during deserialization ([#20132](https://github.com/opensearch-project/OpenSearch/pull/20132))
103103
- Fix negative CPU usage values in node stats ([#19120](https://github.com/opensearch-project/OpenSearch/issues/19120))
104-
- Fix duplicate registration of FieldDataCache dynamic setting ([20140](https://github.com/opensearch-project/OpenSearch/pull/20140))
104+
- Fix duplicate registration of FieldDataCache dynamic setting ([#20140](https://github.com/opensearch-project/OpenSearch/pull/20140))
105+
- Fix array out of bounds during aggregation ([#20204](https://github.com/opensearch-project/OpenSearch/pull/20204))
105106

106107
### Dependencies
107108
- Bump Apache Lucene from 10.3.1 to 10.3.2 ([#20026](https://github.com/opensearch-project/OpenSearch/pull/20026))
@@ -131,7 +132,7 @@ Compatible with OpenSearch and OpenSearch Dashboards version 3.4.0
131132
- Bump `netty` to 4.2.4 ([#19178](https://github.com/opensearch-project/OpenSearch/pull/19178))
132133
- Bump `actions/github-script` from 7 to 8 ([#19946](https://github.com/opensearch-project/OpenSearch/pull/19946))
133134
- Bump `com.google.api:gax-httpjson` from 2.69.0 to 2.72.1 ([#19943](https://github.com/opensearch-project/OpenSearch/pull/19943))
134-
- Update Hadoop to 3.4.2 and enable security (Kerberos) integration tests under JDK-24 and above ([#19952](https://github.com/opensearch-project/OpenSearch/pull/19952))
135+
- Update Hadoop to 3.4.2 and enable security (Kerberos) integration tests under JDK-24 and above ([#19952](https://github.com/opensearch-project/OpenSearch/pull/19952))
135136
- Bump `com.google.cloud:google-cloud-storage` from 2.55.0 to 2.60.0 ([#20023](https://github.com/opensearch-project/OpenSearch/pull/20023))
136137
- Bump `commons-cli:commons-cli` from 1.10.0 to 1.11.0 ([#20022](https://github.com/opensearch-project/OpenSearch/pull/20022))
137138
- Bump `com.squareup.okio:okio` from 3.16.0 to 3.16.3 ([#20025](https://github.com/opensearch-project/OpenSearch/pull/20025))

server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/Ranges.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class Ranges {
1818
byte[][] uppers; // exclusive
1919
int size;
2020
int byteLen;
21-
static ArrayUtil.ByteArrayComparator comparator;
21+
ArrayUtil.ByteArrayComparator comparator;
2222

2323
Ranges(byte[][] lowers, byte[][] uppers) {
2424
this.lowers = lowers;
@@ -55,15 +55,15 @@ public int firstRangeIndex(byte[] globalMin, byte[] globalMax) {
5555
return i;
5656
}
5757

58-
public static int compareByteValue(byte[] value1, byte[] value2) {
58+
public int compareByteValue(byte[] value1, byte[] value2) {
5959
return comparator.compare(value1, 0, value2, 0);
6060
}
6161

62-
public static boolean withinLowerBound(byte[] value, byte[] lowerBound) {
62+
public boolean withinLowerBound(byte[] value, byte[] lowerBound) {
6363
return compareByteValue(value, lowerBound) >= 0;
6464
}
6565

66-
public static boolean withinUpperBound(byte[] value, byte[] upperBound) {
66+
public boolean withinUpperBound(byte[] value, byte[] upperBound) {
6767
return compareByteValue(value, upperBound) < 0;
6868
}
6969
}

server/src/main/java/org/opensearch/search/aggregations/bucket/filterrewrite/rangecollector/AbstractRangeCollector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public boolean iterateRangeEnd(byte[] value, boolean inLeaf) {
5252

5353
@Override
5454
public boolean withinLowerBound(byte[] value) {
55-
return Ranges.withinLowerBound(value, ranges.getLowers()[activeIndex]);
55+
return ranges.withinLowerBound(value, ranges.getLowers()[activeIndex]);
5656
}
5757

5858
@Override
5959
public boolean withinUpperBound(byte[] value) {
60-
return Ranges.withinUpperBound(value, ranges.getUppers()[activeIndex]);
60+
return ranges.withinUpperBound(value, ranges.getUppers()[activeIndex]);
6161
}
6262

6363
@Override

0 commit comments

Comments
 (0)