From d215bed7550b7b59d22fb182a2f0c0d95cdfdc16 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 11 May 2023 08:54:27 -0700 Subject: [PATCH] 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. --- .../xcontent/provider/json/JsonXContentImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentImpl.java b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentImpl.java index 85890c87a3be0..cbd3e7378b6df 100644 --- a/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentImpl.java +++ b/libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/json/JsonXContentImpl.java @@ -10,8 +10,10 @@ import com.fasterxml.jackson.core.JsonEncoding; import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonFactoryBuilder; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.StreamReadConstraints; import org.elasticsearch.xcontent.XContent; import org.elasticsearch.xcontent.XContentBuilder; @@ -44,7 +46,12 @@ public static final XContent jsonXContent() { } static { - jsonFactory = new JsonFactory(); + var builder = new JsonFactoryBuilder(); + // jackson 2.15 introduced a max string length. We have other limits in place to constrain max doc size, + // so here we set to max value (2GiB) so as not to constrain further than those existing limits. + builder.streamReadConstraints(StreamReadConstraints.builder().maxStringLength(Integer.MAX_VALUE).build()); + + jsonFactory = builder.build(); jsonFactory.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true); jsonFactory.configure(JsonParser.Feature.ALLOW_COMMENTS, true); jsonFactory.configure(JsonFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW, false); // this trips on many mappings now...