Skip to content

Commit 95e83a0

Browse files
committed
Merge branch '2.21' into 2.x
2 parents 7fddd2a + c9a45e2 commit 95e83a0

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

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/com/fasterxml/jackson/core/JsonFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,8 @@ protected JsonParser _createParser(Reader r, IOContext ctxt) throws IOException
19441944
*/
19451945
protected JsonParser _createParser(char[] data, int offset, int len, IOContext ctxt,
19461946
boolean recyclable) throws IOException {
1947+
// [core#1548] Validate doc length upfront for fixed buffers
1948+
_streamReadConstraints.validateDocumentLength(len);
19471949
return new ReaderBasedJsonParser(ctxt, _parserFeatures, null, _objectCodec,
19481950
_rootCharSymbols.makeChild(),
19491951
data, offset, offset+len, recyclable);
@@ -1971,6 +1973,8 @@ protected JsonParser _createParser(char[] data, int offset, int len, IOContext c
19711973
*/
19721974
protected JsonParser _createParser(byte[] data, int offset, int len, IOContext ctxt) throws IOException
19731975
{
1976+
// [core#1548] Validate doc length upfront for fixed buffers
1977+
_streamReadConstraints.validateDocumentLength(len);
19741978
return new ByteSourceJsonBootstrapper(ctxt, data, offset, len).constructParser(_parserFeatures,
19751979
_objectCodec, _byteSymbolCanonicalizer, _rootCharSymbols, _factoryFeatures);
19761980
}

src/test/java/com/fasterxml/jackson/core/constraints/LargeDocReadTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ void largeNameWithSmallLimitBytes() throws Exception
5252
} catch (StreamConstraintsException e) {
5353
verifyMaxDocLen(JSON_F_DOC_10K, e);
5454
}
55+
// [core#1548] validate for fixed buffer too
56+
try (JsonParser p = JSON_F_DOC_10K.createParser(utf8Bytes(doc))) {
57+
consumeTokens(p);
58+
fail("expected StreamConstraintsException");
59+
} catch (StreamConstraintsException e) {
60+
verifyMaxDocLen(JSON_F_DOC_10K, e);
61+
}
5562
}
5663

5764
@Test
@@ -64,6 +71,13 @@ void largeNameWithSmallLimitChars() throws Exception
6471
} catch (StreamConstraintsException e) {
6572
verifyMaxDocLen(JSON_F_DOC_10K, e);
6673
}
74+
// [core#1548] validate for fixed buffer too
75+
try (JsonParser p = JSON_F_DOC_10K.createParser(doc.toCharArray())) {
76+
consumeTokens(p);
77+
fail("expected StreamConstraintsException");
78+
} catch (StreamConstraintsException e) {
79+
verifyMaxDocLen(JSON_F_DOC_10K, e);
80+
}
6781
}
6882

6983
@Test

0 commit comments

Comments
 (0)