Skip to content

Commit 240ce6e

Browse files
committed
Merge branch '2.19' into 2.20
2 parents f7193da + 10d2300 commit 240ce6e

7 files changed

Lines changed: 41 additions & 16 deletions

File tree

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected JsonMappingException _invalidSchemaDefinition(JavaType type,
232232
public AvroSchema schemaFrom(InputStream in) throws IOException
233233
{
234234
try {
235-
return new AvroSchema(new Schema.Parser().setValidate(true)
235+
return new AvroSchema(new Schema.Parser()
236236
.parse(in));
237237
} finally {
238238
in.close();
@@ -249,7 +249,7 @@ public AvroSchema schemaFrom(InputStream in) throws IOException
249249
*/
250250
public AvroSchema schemaFrom(String schemaAsString) throws IOException
251251
{
252-
return new AvroSchema(new Schema.Parser().setValidate(true)
252+
return new AvroSchema(new Schema.Parser()
253253
.parse(schemaAsString));
254254
}
255255

@@ -263,7 +263,7 @@ public AvroSchema schemaFrom(String schemaAsString) throws IOException
263263
*/
264264
public AvroSchema schemaFrom(File schemaFile) throws IOException
265265
{
266-
return new AvroSchema(new Schema.Parser().setValidate(true)
266+
return new AvroSchema(new Schema.Parser()
267267
.parse(schemaFile));
268268
}
269269
}

avro/src/test/java/perf/PerfBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected GenericRecord itemToRecord(MediaItem item) throws IOException
137137
}
138138

139139
protected static AvroSchema itemSchema() {
140-
return new AvroSchema(new Schema.Parser().setValidate(true).parse(JVM_SERIALIZERS_SCHEMA_STR));
140+
return new AvroSchema(new Schema.Parser().parse(JVM_SERIALIZERS_SCHEMA_STR));
141141
}
142142

143143
protected static MediaItem buildItem()

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ protected JsonParser _createParser(char[] data, int offset, int len, IOContext c
425425
@Override
426426
protected CBORParser _createParser(byte[] data, int offset, int len, IOContext ctxt) throws IOException
427427
{
428+
// [core#1548] Validate doc length up front for fixed buffers
429+
_streamReadConstraints.validateDocumentLength(len);
428430
return new CBORParserBootstrapper(ctxt, data, offset, len).constructParser(
429431
_factoryFeatures, _parserFeatures, _formatParserFeatures,
430432
_objectCodec, _byteSymbolCanonicalizer);

cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/gen/constraints/LongDocumentCBORReadTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88

99
import com.fasterxml.jackson.core.*;
1010
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
11-
import com.fasterxml.jackson.databind.ObjectMapper;
11+
1212
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
1313
import com.fasterxml.jackson.dataformat.cbor.CBORTestBase;
14+
import com.fasterxml.jackson.dataformat.cbor.databind.CBORMapper;
1415

1516
import static org.junit.jupiter.api.Assertions.assertTrue;
1617
import static org.junit.jupiter.api.Assertions.fail;
1718

1819
public class LongDocumentCBORReadTest extends CBORTestBase
1920
{
20-
private final ObjectMapper MAPPER_VANILLA = cborMapper();
21+
private final CBORMapper MAPPER_VANILLA = cborMapper();
2122

22-
private final ObjectMapper MAPPER_CONSTRAINED = cborMapper(
23+
private final CBORMapper MAPPER_CONSTRAINED = cborMapper(
2324
CBORFactory.builder()
2425
// limit to 100kB doc reads
2526
.streamReadConstraints(StreamReadConstraints.builder()
@@ -32,13 +33,20 @@ public void testLongDocumentConstraint() throws Exception
3233
{
3334
// Need a bit longer than minimum since checking is approximate, not exact
3435
byte[] doc = createBigDoc(60_000);
35-
// Must read from `InputStream` as validation is during "loadMore()":
36-
try (JsonParser p = MAPPER_CONSTRAINED.createParser(new ByteArrayInputStream(doc))) {
36+
_testLongDocumentConstraint(doc, true);
37+
// [dataformats-binary#649] fixed buffer too
38+
_testLongDocumentConstraint(doc, false);
39+
}
40+
41+
private void _testLongDocumentConstraint(byte[] doc, boolean stream) throws Exception
42+
{
43+
try (JsonParser p = stream
44+
? MAPPER_CONSTRAINED.createParser(new ByteArrayInputStream(doc))
45+
: MAPPER_CONSTRAINED.createParser(doc, 0, doc.length)) {
3746
while (p.nextToken() != null) { }
3847
fail("expected StreamConstraintsException");
3948
} catch (StreamConstraintsException e) {
4049
final String msg = e.getMessage();
41-
4250
assertTrue(msg.contains("Document length ("));
4351
assertTrue(msg.contains("exceeds the maximum allowed (50000"));
4452
}

release-notes/VERSION-2.x

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ No changes since 2.19.1
9898
#571: Unable to deserialize a pojo with IonStruct
9999
(reported, fix contributed by Josh C)
100100

101+
2.18.6 (not yet released)
102+
103+
#645: (avro) Remove use of Avro `Schema.Parser().setValidate()` to allow
104+
use of Avro core 1.12.1 (2.x)
105+
#649: (cbor, smile) `StreamReadConstraints.maxDocumentLength` not checked
106+
when creating parser with fixed buffer
107+
101108
2.18.5 (27-Oct-2025)
102109

103110
#599: (cbor) Unable to deserialize stringref-enabled CBOR with ignored properties

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ protected JsonParser _createParser(char[] data, int offset, int len, IOContext c
458458
@Override
459459
protected SmileParser _createParser(byte[] data, int offset, int len, IOContext ctxt) throws IOException
460460
{
461+
// [core#1548] Validate doc length up front for fixed buffers
462+
_streamReadConstraints.validateDocumentLength(len);
461463
return new SmileParserBootstrapper(ctxt, data, offset, len).constructParser(
462464
_factoryFeatures, _parserFeatures, _smileParserFeatures,
463465
_objectCodec, _byteSymbolCanonicalizer);

smile/src/test/java/com/fasterxml/jackson/dataformat/smile/constraints/LongDocumentSmileReadTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import com.fasterxml.jackson.core.*;
1010
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
11-
import com.fasterxml.jackson.databind.ObjectMapper;
1211
import com.fasterxml.jackson.dataformat.smile.BaseTestForSmile;
1312
import com.fasterxml.jackson.dataformat.smile.SmileFactory;
1413
import com.fasterxml.jackson.dataformat.smile.databind.SmileMapper;
@@ -17,9 +16,9 @@
1716

1817
public class LongDocumentSmileReadTest extends BaseTestForSmile
1918
{
20-
private final ObjectMapper MAPPER_VANILLA = new SmileMapper();
19+
private final SmileMapper MAPPER_VANILLA = new SmileMapper();
2120

22-
private final ObjectMapper MAPPER_CONSTRAINED = new SmileMapper(
21+
private final SmileMapper MAPPER_CONSTRAINED = new SmileMapper(
2322
SmileFactory.builder()
2423
// limit to 100kB doc reads
2524
.streamReadConstraints(StreamReadConstraints.builder()
@@ -32,13 +31,20 @@ public void testLongDocumentConstraint() throws Exception
3231
{
3332
// Need a bit longer than minimum since checking is approximate, not exact
3433
byte[] doc = createBigDoc(60_000);
35-
// Must read from `InputStream` as validation is during "loadMore()":
36-
try (JsonParser p = MAPPER_CONSTRAINED.createParser(new ByteArrayInputStream(doc))) {
34+
_testLongDocumentConstraint(doc, true);
35+
// [dataformats-binary#649] fixed buffer too
36+
_testLongDocumentConstraint(doc, false);
37+
}
38+
39+
private void _testLongDocumentConstraint(byte[] doc, boolean stream) throws Exception
40+
{
41+
try (JsonParser p = stream
42+
? MAPPER_CONSTRAINED.createParser(new ByteArrayInputStream(doc))
43+
: MAPPER_CONSTRAINED.createParser(doc, 0, doc.length)) {
3744
while (p.nextToken() != null) { }
3845
fail("expected StreamConstraintsException");
3946
} catch (StreamConstraintsException e) {
4047
final String msg = e.getMessage();
41-
4248
assertTrue(msg.contains("Document length ("));
4349
assertTrue(msg.contains("exceeds the maximum allowed (50000"));
4450
}

0 commit comments

Comments
 (0)