Skip to content

Commit 1208c02

Browse files
authored
Relax limit on max string size (#96031)
Jackson 2.15 introduced a (rough) maximum limit on string length. This commit relaxes that limit to its maximum size, leaving document size constraints to other existing limits in the system. We can revisit whether string length within a document should be independently constrainted later.
1 parent 40a22d1 commit 1208c02

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentImpl.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010

1111
import com.fasterxml.jackson.core.JsonEncoding;
1212
import com.fasterxml.jackson.core.JsonFactory;
13+
import com.fasterxml.jackson.core.JsonFactoryBuilder;
1314
import com.fasterxml.jackson.core.JsonGenerator;
1415
import com.fasterxml.jackson.core.JsonParser;
16+
import com.fasterxml.jackson.core.StreamReadConstraints;
1517

1618
import org.elasticsearch.xcontent.XContent;
1719
import org.elasticsearch.xcontent.XContentBuilder;
@@ -44,7 +46,12 @@ public static final XContent jsonXContent() {
4446
}
4547

4648
static {
47-
jsonFactory = new JsonFactory();
49+
var builder = new JsonFactoryBuilder();
50+
// jackson 2.15 introduced a max string length. We have other limits in place to constrain max doc size,
51+
// so here we set to max value (2GiB) so as not to constrain further than those existing limits.
52+
builder.streamReadConstraints(StreamReadConstraints.builder().maxStringLength(Integer.MAX_VALUE).build());
53+
54+
jsonFactory = builder.build();
4855
jsonFactory.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
4956
jsonFactory.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
5057
jsonFactory.configure(JsonFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW, false); // this trips on many mappings now...

0 commit comments

Comments
 (0)