Skip to content

Commit 2e240cb

Browse files
committed
Relax limit on max string size in CBOR, Smile, YAML
Remove the rough limit on string length from Jackson 2.15. The limit was already relaxed for JSON in elastic#96031, this extends that change to other XContent types. Refs: elastic#96031
1 parent 948960c commit 2e240cb

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/cbor/CborXContentImpl.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.fasterxml.jackson.core.JsonEncoding;
1212
import com.fasterxml.jackson.core.JsonGenerator;
1313
import com.fasterxml.jackson.core.JsonParser;
14+
import com.fasterxml.jackson.core.StreamReadConstraints;
1415
import com.fasterxml.jackson.dataformat.cbor.CBORConstants;
1516
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
1617

@@ -45,7 +46,9 @@ public static XContent cborXContent() {
4546
}
4647

4748
static {
48-
cborFactory = new CBORFactory();
49+
var builder = CBORFactory.builder();
50+
builder.streamReadConstraints(StreamReadConstraints.builder().maxStringLength(Integer.MAX_VALUE).build());
51+
cborFactory = builder.build();
4952
cborFactory.configure(CBORFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW, false); // this trips on many mappings now...
5053
// Do not automatically close unclosed objects/arrays in com.fasterxml.jackson.dataformat.cbor.CBORGenerator#close() method
5154
cborFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false);

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/smile/SmileXContentImpl.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.fasterxml.jackson.core.JsonEncoding;
1212
import com.fasterxml.jackson.core.JsonGenerator;
1313
import com.fasterxml.jackson.core.JsonParser;
14+
import com.fasterxml.jackson.core.StreamReadConstraints;
1415
import com.fasterxml.jackson.dataformat.smile.SmileConstants;
1516
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
1617
import com.fasterxml.jackson.dataformat.smile.SmileGenerator;
@@ -45,7 +46,9 @@ public static XContent smileXContent() {
4546
}
4647

4748
static {
48-
smileFactory = new SmileFactory();
49+
var builder = SmileFactory.builder();
50+
builder.streamReadConstraints(StreamReadConstraints.builder().maxStringLength(Integer.MAX_VALUE).build());
51+
smileFactory = builder.build();
4952
// for now, this is an overhead, might make sense for web sockets
5053
smileFactory.configure(SmileGenerator.Feature.ENCODE_BINARY_AS_7BIT, false);
5154
smileFactory.configure(SmileFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW, false); // this trips on many mappings now...

libs/x-content/impl/src/main/java/org/elasticsearch/xcontent/provider/yaml/YamlXContentImpl.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import com.fasterxml.jackson.core.JsonEncoding;
1212
import com.fasterxml.jackson.core.JsonParser;
13+
import com.fasterxml.jackson.core.StreamReadConstraints;
1314
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
1415

1516
import org.elasticsearch.xcontent.XContent;
@@ -42,7 +43,9 @@ public static XContent yamlXContent() {
4243
}
4344

4445
static {
45-
yamlFactory = new YAMLFactory();
46+
var builder = YAMLFactory.builder();
47+
builder.streamReadConstraints(StreamReadConstraints.builder().maxStringLength(Integer.MAX_VALUE).build());
48+
yamlFactory = builder.build();
4649
yamlFactory.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true);
4750
yamlFactory.configure(JsonParser.Feature.USE_FAST_DOUBLE_PARSER, true);
4851
yamlXContent = new YamlXContentImpl();

0 commit comments

Comments
 (0)