Skip to content

Commit 861a0d3

Browse files
committed
Merge branch '2.19' into 2.20
2 parents a4d149f + 6659bb8 commit 861a0d3

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

release-notes/VERSION-2.x

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ No changes since 2.19.1
8686
(requested by Ilenia S)
8787
(fixed by @pjfanning)
8888

89+
2.18.7 (not yet released)
90+
91+
#1570: Fail parsing from `DataInput` if
92+
`StreamReadConstraints.getMaxDocumentLength()` set [GHSA-2m67-wjpj-xhg9]
93+
(fix by @cowtowncoder, w/ Claude code)
94+
8995
2.18.6 (22-Feb-2026)
9096

9197
#1512: Number-parsing fix for `UTF8DataInputJsonParser`

src/main/java/com/fasterxml/jackson/core/JsonFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.List;
1212
import java.util.Objects;
1313

14+
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
1415
import com.fasterxml.jackson.core.format.InputAccessor;
1516
import com.fasterxml.jackson.core.format.MatchStrength;
1617
import com.fasterxml.jackson.core.io.*;
@@ -1996,6 +1997,13 @@ protected JsonParser _createParser(DataInput input, IOContext ctxt) throws IOExc
19961997
// 13-May-2016, tatu: Need to take care not to accidentally create JSON parser for
19971998
// non-JSON input.
19981999
_requireJSONFactory("InputData source not (yet?) supported for this format (%s)");
2000+
// [core#1570] DataInput reads byte-by-byte so we cannot efficiently enforce
2001+
// maxDocumentLength. Fail fast if the limit has been configured.
2002+
if (_streamReadConstraints.hasMaxDocumentLength()) {
2003+
throw new StreamConstraintsException(
2004+
"Can not enforce `StreamReadConstraints.getMaxDocumentLength()` limit with `DataInput`-backed parser: "
2005+
+"use other input source types, or remove the max-document-length limit");
2006+
}
19992007
// Also: while we can't do full bootstrapping (due to read-ahead limitations), should
20002008
// at least handle possible UTF-8 BOM
20012009
int firstByte = ByteSourceJsonBootstrapper.skipUTF8BOM(input);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.fasterxml.jackson.core.async.AsyncTestBase;
99
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
1010
import com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper;
11+
import com.fasterxml.jackson.core.testsupport.MockDataInput;
1112

1213
import static org.junit.jupiter.api.Assertions.assertEquals;
1314
import static org.junit.jupiter.api.Assertions.fail;
@@ -102,6 +103,29 @@ void largeNameWithSmallLimitAsync() throws Exception
102103
}
103104
}
104105

106+
// [core#1570] Should fail fast when DataInput used with maxDocumentLength set
107+
@Test
108+
void dataInputWithDocLengthLimitFails() throws Exception
109+
{
110+
final String doc = generateJSON(100);
111+
try (JsonParser p = JSON_F_DOC_10K.createParser(new MockDataInput(doc))) {
112+
fail("expected StreamConstraintsException");
113+
} catch (StreamConstraintsException e) {
114+
verifyException(e, "DataInput");
115+
verifyException(e, "maxDocumentLength");
116+
}
117+
}
118+
119+
// [core#1570] DataInput without maxDocumentLength should still work
120+
@Test
121+
void dataInputWithoutDocLengthLimitWorks() throws Exception
122+
{
123+
final String doc = generateJSON(100);
124+
try (JsonParser p = JSON_F_DEFAULT.createParser(new MockDataInput(doc))) {
125+
consumeTokens(p);
126+
}
127+
}
128+
105129
@Test
106130
void tokenLimitBytes() throws Exception {
107131
final String doc = generateJSON(StreamReadConstraints.defaults().getMaxNameLength() - 100);

0 commit comments

Comments
 (0)