Skip to content

Commit 09d0888

Browse files
committed
Merge branch '2.x' into 3.x
2 parents 8c99dc0 + 95e83a0 commit 09d0888

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ JSON library.
1515
=== Releases ===
1616
------------------------------------------------------------------------
1717

18+
3.1.0 (not yet released)
19+
20+
#1548: `StreamReadConstraints.maxDocumentLength` not checked when
21+
creating parser with fixed buffer
22+
1823
3.1.0-rc1 (27-Jan-2026)
1924

2025
#784: Optional leading plus sign not included in textual value of any

release-notes/VERSION-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ a pure JSON library.
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
2.21.1 (not yet released)
18+
19+
#1548: `StreamReadConstraints.maxDocumentLength` not checked when
20+
creating parser with fixed buffer
21+
1722
2.21.0 (18-Jan-2026)
1823

1924
#363: UTF-8 decoding should fail on Surrogate characters (0xD800 - 0xDFFF)

src/main/java/tools/jackson/core/json/JsonFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ protected JsonParser _createParser(ObjectReadContext readCtxt, IOContext ioCtxt,
422422
boolean recyclable) throws JacksonException
423423
{
424424
_checkRangeBoundsForCharArray(data, offset, len);
425+
// [core#1548] Validate doc length up front for fixed buffers
426+
_streamReadConstraints.validateDocumentLength(len);
425427
return new ReaderBasedJsonParser(readCtxt, ioCtxt,
426428
readCtxt.getStreamReadFeatures(_streamReadFeatures),
427429
readCtxt.getFormatReadFeatures(_formatReadFeatures),
@@ -436,6 +438,8 @@ protected JsonParser _createParser(ObjectReadContext readCtxt, IOContext ioCtxt,
436438
throws JacksonException
437439
{
438440
_checkRangeBoundsForByteArray(data, offset, len);
441+
// [core#1548] Validate doc length up front for fixed buffers
442+
_streamReadConstraints.validateDocumentLength(len);
439443
return new ByteSourceJsonBootstrapper(ioCtxt, data, offset, len)
440444
.constructParser(readCtxt,
441445
readCtxt.getStreamReadFeatures(_streamReadFeatures),

src/test/java/tools/jackson/core/unittest/constraints/LargeDocReadTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.junit.jupiter.api.Test;
66

77
import tools.jackson.core.JsonParser;
8+
import tools.jackson.core.ObjectReadContext;
89
import tools.jackson.core.StreamReadConstraints;
910
import tools.jackson.core.exc.StreamConstraintsException;
1011
import tools.jackson.core.json.JsonFactory;
@@ -54,6 +55,14 @@ void largeNameWithSmallLimitBytes() throws Exception
5455
} catch (StreamConstraintsException e) {
5556
verifyMaxDocLen(JSON_F_DOC_10K, e);
5657
}
58+
// [core#1548] validate for fixed buffer too
59+
try (JsonParser p = JSON_F_DOC_10K.createParser(ObjectReadContext.empty(),
60+
utf8Bytes(doc))) {
61+
consumeTokens(p);
62+
fail("expected StreamConstraintsException");
63+
} catch (StreamConstraintsException e) {
64+
verifyMaxDocLen(JSON_F_DOC_10K, e);
65+
}
5766
}
5867

5968
@Test
@@ -66,6 +75,14 @@ void largeNameWithSmallLimitChars() throws Exception
6675
} catch (StreamConstraintsException e) {
6776
verifyMaxDocLen(JSON_F_DOC_10K, e);
6877
}
78+
// [core#1548] validate for fixed buffer too
79+
try (JsonParser p = JSON_F_DOC_10K.createParser(ObjectReadContext.empty(),
80+
doc.toCharArray())) {
81+
consumeTokens(p);
82+
fail("expected StreamConstraintsException");
83+
} catch (StreamConstraintsException e) {
84+
verifyMaxDocLen(JSON_F_DOC_10K, e);
85+
}
6986
}
7087

7188
@Test

0 commit comments

Comments
 (0)