Skip to content

Commit 701cd6a

Browse files
authored
Implement document length tracking for DataInput-backed JSON parsers via subclass (#1575)
1 parent 93a8a16 commit 701cd6a

File tree

5 files changed

+169
-109
lines changed

5 files changed

+169
-109
lines changed

release-notes/VERSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ JSON library.
2323
(implemented by @pjfanning)
2424
#1545: Increase Android baseline from 26 to 34 in Jackson 3.2
2525
#1564: Add `SimpleStreamReadContext.rollbackValueRead()` method
26-
#1570: Fail parsing from `DataInput` if
27-
`StreamReadConstraints.getMaxDocumentLength()` set
28-
(fix by @cowtowncoder, w/ Claude code)
26+
#1575: Implement document length tracking for `DataInput`-backed
27+
JSON parsers via subclass
28+
(implemented by @pjfanning)
2929
#1576: Use Java 17 intrinstics for long multiplication
3030
(contributed by @xtonik)
3131

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

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

1111
import tools.jackson.core.*;
1212
import tools.jackson.core.base.TextualTSFactory;
13-
import tools.jackson.core.exc.StreamConstraintsException;
1413
import tools.jackson.core.io.*;
1514
import tools.jackson.core.json.async.NonBlockingByteArrayJsonParser;
1615
import tools.jackson.core.json.async.NonBlockingByteBufferJsonParser;
@@ -453,17 +452,17 @@ protected JsonParser _createParser(ObjectReadContext readCtxt, IOContext ioCtxt,
453452
DataInput input)
454453
throws JacksonException
455454
{
456-
// [core#1570] DataInput reads byte-by-byte so we cannot efficiently enforce
457-
// maxDocumentLength. Fail fast if the limit has been configured.
458-
if (_streamReadConstraints.hasMaxDocumentLength()) {
459-
throw new StreamConstraintsException(
460-
"Can not enforce `StreamReadConstraints.getMaxDocumentLength()` limit with `DataInput`-backed parser: "
461-
+"use other input source types, or remove the max-document-length limit");
462-
}
463455
// Also: while we can't do full bootstrapping (due to read-ahead limitations), should
464456
// at least handle possible UTF-8 BOM
465457
int firstByte = ByteSourceJsonBootstrapper.skipUTF8BOM(input);
466458
ByteQuadsCanonicalizer can = _byteSymbolCanonicalizer.makeChildOrPlaceholder(_factoryFeatures);
459+
// [core#1575]: Support max doc length constraints with separate impl
460+
if (_streamReadConstraints.hasMaxDocumentLength()) {
461+
return new UTF8DataInputWithDocLengthJsonParser(readCtxt, ioCtxt,
462+
readCtxt.getStreamReadFeatures(_streamReadFeatures),
463+
readCtxt.getFormatReadFeatures(_formatReadFeatures),
464+
input, can, firstByte);
465+
}
467466
return new UTF8DataInputJsonParser(readCtxt, ioCtxt,
468467
readCtxt.getStreamReadFeatures(_streamReadFeatures),
469468
readCtxt.getFormatReadFeatures(_formatReadFeatures),

0 commit comments

Comments
 (0)