Skip to content

Commit 5c82ab8

Browse files
authored
Ensure Jackson default maximums introduced in 2.16.0 do not conflict with OpenSearch settings (#11811)
* Ensure Jackson default maximums introduced in 2.16.0 do not conflict with OpenSearch settings Signed-off-by: Andriy Redko <andriy.redko@aiven.io> * Address code review comments Signed-off-by: Andriy Redko <andriy.redko@aiven.io> * Address code review comments Signed-off-by: Andriy Redko <andriy.redko@aiven.io> --------- Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
1 parent a90b6b6 commit 5c82ab8

File tree

56 files changed

+411
-48
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+411
-48
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
194194
- Capture information for additional query types and aggregation types ([#11582](https://github.com/opensearch-project/OpenSearch/pull/11582))
195195
- Use slice_size == shard_size heuristic in terms aggs for concurrent segment search and properly calculate the doc_count_error ([#11732](https://github.com/opensearch-project/OpenSearch/pull/11732))
196196
- Added Support for dynamically adding SearchRequestOperationsListeners with SearchRequestOperationsCompositeListenerFactory ([#11526](https://github.com/opensearch-project/OpenSearch/pull/11526))
197+
- Ensure Jackson default maximums introduced in 2.16.0 do not conflict with OpenSearch settings ([#11890](https://github.com/opensearch-project/OpenSearch/pull/11890))
197198

198199
### Deprecated
199200

buildSrc/version.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ bundled_jdk = 21.0.1+12
77
# optional dependencies
88
spatial4j = 0.7
99
jts = 1.15.0
10-
jackson = 2.16.0
11-
jackson_databind = 2.16.0
10+
jackson = 2.16.1
11+
jackson_databind = 2.16.1
1212
snakeyaml = 2.1
1313
icu4j = 70.1
1414
supercsv = 2.4.0

client/sniffer/licenses/jackson-core-2.16.0.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9456bb3cdd0f79f91a5f730a1b1bb041a380c91f

distribution/tools/upgrade-cli/licenses/jackson-annotations-2.16.0.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fd441d574a71e7d10a4f73de6609f881d8cdfeec

distribution/tools/upgrade-cli/licenses/jackson-databind-2.16.0.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
02a16efeb840c45af1e2f31753dfe76795278b73

libs/core/licenses/jackson-core-2.16.0.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9456bb3cdd0f79f91a5f730a1b1bb041a380c91f

libs/x-content/licenses/jackson-core-2.16.0.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9456bb3cdd0f79f91a5f730a1b1bb041a380c91f

libs/x-content/licenses/jackson-dataformat-cbor-2.16.0.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1be7098dccc079171464dca7e386bd8df623b031

libs/x-content/licenses/jackson-dataformat-smile-2.16.0.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c4ddbc5277670f2e56b1f5e44e83afa748bcb125

libs/x-content/licenses/jackson-dataformat-yaml-2.16.0.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8e4f1923d73cd55f2b4c0d56ee4ed80419297354
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.common.xcontent;
10+
11+
import com.fasterxml.jackson.core.StreamReadConstraints;
12+
13+
import org.opensearch.common.annotation.InternalApi;
14+
15+
/**
16+
* Consolidates the XContent constraints (primarily reflecting Jackson's {@link StreamReadConstraints} constraints)
17+
*
18+
* @opensearch.internal
19+
*/
20+
@InternalApi
21+
public interface XContentContraints {
22+
final String DEFAULT_MAX_STRING_LEN_PROPERTY = "opensearch.xcontent.string.length.max";
23+
final String DEFAULT_MAX_NAME_LEN_PROPERTY = "opensearch.xcontent.name.length.max";
24+
final String DEFAULT_MAX_DEPTH_PROPERTY = "opensearch.xcontent.depth.max";
25+
26+
final int DEFAULT_MAX_STRING_LEN = Integer.parseInt(System.getProperty(DEFAULT_MAX_STRING_LEN_PROPERTY, "50000000" /* ~50 Mb */));
27+
28+
final int DEFAULT_MAX_NAME_LEN = Integer.parseInt(
29+
System.getProperty(DEFAULT_MAX_NAME_LEN_PROPERTY, "50000" /* StreamReadConstraints.DEFAULT_MAX_NAME_LEN */)
30+
);
31+
32+
final int DEFAULT_MAX_DEPTH = Integer.parseInt(
33+
System.getProperty(DEFAULT_MAX_DEPTH_PROPERTY, "1000" /* StreamReadConstraints.DEFAULT_MAX_DEPTH */)
34+
);
35+
}

libs/x-content/src/main/java/org/opensearch/common/xcontent/cbor/CborXContent.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
import com.fasterxml.jackson.core.JsonParser;
3838
import com.fasterxml.jackson.core.StreamReadConstraints;
3939
import com.fasterxml.jackson.core.StreamReadFeature;
40+
import com.fasterxml.jackson.core.StreamWriteConstraints;
4041
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
4142

43+
import org.opensearch.common.xcontent.XContentContraints;
4244
import org.opensearch.common.xcontent.XContentType;
4345
import org.opensearch.core.xcontent.DeprecationHandler;
4446
import org.opensearch.core.xcontent.MediaType;
@@ -58,11 +60,7 @@
5860
/**
5961
* A CBOR based content implementation using Jackson.
6062
*/
61-
public class CborXContent implements XContent {
62-
public static final int DEFAULT_MAX_STRING_LEN = Integer.parseInt(
63-
System.getProperty("opensearch.xcontent.string.length.max", "50000000" /* ~50 Mb */)
64-
);
65-
63+
public class CborXContent implements XContent, XContentContraints {
6664
public static XContentBuilder contentBuilder() throws IOException {
6765
return XContentBuilder.builder(cborXContent);
6866
}
@@ -76,7 +74,14 @@ public static XContentBuilder contentBuilder() throws IOException {
7674
// Do not automatically close unclosed objects/arrays in com.fasterxml.jackson.dataformat.cbor.CBORGenerator#close() method
7775
cborFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false);
7876
cborFactory.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true);
79-
cborFactory.setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(DEFAULT_MAX_STRING_LEN).build());
77+
cborFactory.setStreamWriteConstraints(StreamWriteConstraints.builder().maxNestingDepth(DEFAULT_MAX_DEPTH).build());
78+
cborFactory.setStreamReadConstraints(
79+
StreamReadConstraints.builder()
80+
.maxStringLength(DEFAULT_MAX_STRING_LEN)
81+
.maxNameLength(DEFAULT_MAX_NAME_LEN)
82+
.maxNestingDepth(DEFAULT_MAX_DEPTH)
83+
.build()
84+
);
8085
cborFactory.configure(StreamReadFeature.USE_FAST_DOUBLE_PARSER.mappedFeature(), true);
8186
cborXContent = new CborXContent();
8287
}

libs/x-content/src/main/java/org/opensearch/common/xcontent/json/JsonXContent.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
import com.fasterxml.jackson.core.JsonParser;
3939
import com.fasterxml.jackson.core.StreamReadConstraints;
4040
import com.fasterxml.jackson.core.StreamReadFeature;
41+
import com.fasterxml.jackson.core.StreamWriteConstraints;
4142

43+
import org.opensearch.common.xcontent.XContentContraints;
4244
import org.opensearch.common.xcontent.XContentType;
4345
import org.opensearch.core.xcontent.DeprecationHandler;
4446
import org.opensearch.core.xcontent.MediaType;
@@ -57,11 +59,7 @@
5759
/**
5860
* A JSON based content implementation using Jackson.
5961
*/
60-
public class JsonXContent implements XContent {
61-
public static final int DEFAULT_MAX_STRING_LEN = Integer.parseInt(
62-
System.getProperty("opensearch.xcontent.string.length.max", "50000000" /* ~50 Mb */)
63-
);
64-
62+
public class JsonXContent implements XContent, XContentContraints {
6563
public static XContentBuilder contentBuilder() throws IOException {
6664
return XContentBuilder.builder(jsonXContent);
6765
}
@@ -78,7 +76,14 @@ public static XContentBuilder contentBuilder() throws IOException {
7876
// Do not automatically close unclosed objects/arrays in com.fasterxml.jackson.core.json.UTF8JsonGenerator#close() method
7977
jsonFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false);
8078
jsonFactory.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true);
81-
jsonFactory.setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(DEFAULT_MAX_STRING_LEN).build());
79+
jsonFactory.setStreamWriteConstraints(StreamWriteConstraints.builder().maxNestingDepth(DEFAULT_MAX_DEPTH).build());
80+
jsonFactory.setStreamReadConstraints(
81+
StreamReadConstraints.builder()
82+
.maxStringLength(DEFAULT_MAX_STRING_LEN)
83+
.maxNameLength(DEFAULT_MAX_NAME_LEN)
84+
.maxNestingDepth(DEFAULT_MAX_DEPTH)
85+
.build()
86+
);
8287
jsonFactory.configure(StreamReadFeature.USE_FAST_DOUBLE_PARSER.mappedFeature(), true);
8388
jsonXContent = new JsonXContent();
8489
}

libs/x-content/src/main/java/org/opensearch/common/xcontent/smile/SmileXContent.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
import com.fasterxml.jackson.core.JsonParser;
3838
import com.fasterxml.jackson.core.StreamReadConstraints;
3939
import com.fasterxml.jackson.core.StreamReadFeature;
40+
import com.fasterxml.jackson.core.StreamWriteConstraints;
4041
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
4142
import com.fasterxml.jackson.dataformat.smile.SmileGenerator;
4243

44+
import org.opensearch.common.xcontent.XContentContraints;
4345
import org.opensearch.common.xcontent.XContentType;
4446
import org.opensearch.core.xcontent.DeprecationHandler;
4547
import org.opensearch.core.xcontent.MediaType;
@@ -58,11 +60,7 @@
5860
/**
5961
* A Smile based content implementation using Jackson.
6062
*/
61-
public class SmileXContent implements XContent {
62-
public static final int DEFAULT_MAX_STRING_LEN = Integer.parseInt(
63-
System.getProperty("opensearch.xcontent.string.length.max", "50000000" /* ~50 Mb */)
64-
);
65-
63+
public class SmileXContent implements XContent, XContentContraints {
6664
public static XContentBuilder contentBuilder() throws IOException {
6765
return XContentBuilder.builder(smileXContent);
6866
}
@@ -78,7 +76,14 @@ public static XContentBuilder contentBuilder() throws IOException {
7876
// Do not automatically close unclosed objects/arrays in com.fasterxml.jackson.dataformat.smile.SmileGenerator#close() method
7977
smileFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false);
8078
smileFactory.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true);
81-
smileFactory.setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(DEFAULT_MAX_STRING_LEN).build());
79+
smileFactory.setStreamWriteConstraints(StreamWriteConstraints.builder().maxNestingDepth(DEFAULT_MAX_DEPTH).build());
80+
smileFactory.setStreamReadConstraints(
81+
StreamReadConstraints.builder()
82+
.maxStringLength(DEFAULT_MAX_STRING_LEN)
83+
.maxNameLength(DEFAULT_MAX_NAME_LEN)
84+
.maxNestingDepth(DEFAULT_MAX_DEPTH)
85+
.build()
86+
);
8287
smileFactory.configure(StreamReadFeature.USE_FAST_DOUBLE_PARSER.mappedFeature(), true);
8388
smileXContent = new SmileXContent();
8489
}

libs/x-content/src/main/java/org/opensearch/common/xcontent/yaml/YamlXContent.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
import com.fasterxml.jackson.core.JsonParser;
3737
import com.fasterxml.jackson.core.StreamReadConstraints;
3838
import com.fasterxml.jackson.core.StreamReadFeature;
39+
import com.fasterxml.jackson.core.StreamWriteConstraints;
3940
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
4041

42+
import org.opensearch.common.xcontent.XContentContraints;
4143
import org.opensearch.common.xcontent.XContentType;
4244
import org.opensearch.core.xcontent.DeprecationHandler;
4345
import org.opensearch.core.xcontent.MediaType;
@@ -56,11 +58,7 @@
5658
/**
5759
* A YAML based content implementation using Jackson.
5860
*/
59-
public class YamlXContent implements XContent {
60-
public static final int DEFAULT_MAX_STRING_LEN = Integer.parseInt(
61-
System.getProperty("opensearch.xcontent.string.length.max", "50000000" /* ~50 Mb */)
62-
);
63-
61+
public class YamlXContent implements XContent, XContentContraints {
6462
public static XContentBuilder contentBuilder() throws IOException {
6563
return XContentBuilder.builder(yamlXContent);
6664
}
@@ -71,7 +69,14 @@ public static XContentBuilder contentBuilder() throws IOException {
7169
static {
7270
yamlFactory = new YAMLFactory();
7371
yamlFactory.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true);
74-
yamlFactory.setStreamReadConstraints(StreamReadConstraints.builder().maxStringLength(DEFAULT_MAX_STRING_LEN).build());
72+
yamlFactory.setStreamWriteConstraints(StreamWriteConstraints.builder().maxNestingDepth(DEFAULT_MAX_DEPTH).build());
73+
yamlFactory.setStreamReadConstraints(
74+
StreamReadConstraints.builder()
75+
.maxStringLength(DEFAULT_MAX_STRING_LEN)
76+
.maxNameLength(DEFAULT_MAX_NAME_LEN)
77+
.maxNestingDepth(DEFAULT_MAX_DEPTH)
78+
.build()
79+
);
7580
yamlFactory.configure(StreamReadFeature.USE_FAST_DOUBLE_PARSER.mappedFeature(), true);
7681
yamlXContent = new YamlXContent();
7782
}

0 commit comments

Comments
 (0)