@@ -182,6 +182,11 @@ public int getFirstTag() {
182
182
*/
183
183
protected final IOContext _ioContext ;
184
184
185
+ /**
186
+ * @since 2.17
187
+ */
188
+ protected final StreamReadConstraints _streamReadConstraints ;
189
+
185
190
/**
186
191
* Flag that indicates whether parser is closed or not. Gets
187
192
* set when parser is either closed by explicit call
@@ -532,11 +537,13 @@ public CBORParser(IOContext ctxt, int parserFeatures, int cborFeatures,
532
537
533
538
_tokenInputRow = -1 ;
534
539
_tokenInputCol = -1 ;
540
+
541
+ _streamReadConstraints = ctxt .streamReadConstraints ();
535
542
}
536
543
537
544
@ Override
538
545
public StreamReadConstraints streamReadConstraints () {
539
- return _ioContext . streamReadConstraints () ;
546
+ return _streamReadConstraints ;
540
547
}
541
548
542
549
@ Override
@@ -1127,7 +1134,7 @@ protected JsonToken _handleTaggedBinary(TagList tags) throws IOException
1127
1134
if (_binaryValue .length == 0 ) {
1128
1135
_numberBigInt = BigInteger .ZERO ;
1129
1136
} else {
1130
- streamReadConstraints () .validateIntegerLength (_binaryValue .length );
1137
+ _streamReadConstraints .validateIntegerLength (_binaryValue .length );
1131
1138
BigInteger nr = new BigInteger (_binaryValue );
1132
1139
if (neg ) {
1133
1140
nr = nr .negate ();
@@ -2163,7 +2170,7 @@ protected void convertNumberToBigInteger() throws IOException
2163
2170
{
2164
2171
if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
2165
2172
// here it'll just get truncated, no exceptions thrown
2166
- streamReadConstraints () .validateBigIntegerScale (_numberBigDecimal .scale ());
2173
+ _streamReadConstraints .validateBigIntegerScale (_numberBigDecimal .scale ());
2167
2174
_numberBigInt = _numberBigDecimal .toBigInteger ();
2168
2175
} else if ((_numTypesValid & NR_LONG ) != 0 ) {
2169
2176
_numberBigInt = BigInteger .valueOf (_numberLong );
@@ -2232,7 +2239,7 @@ protected void convertNumberToBigDecimal() throws IOException
2232
2239
if (text == null ) {
2233
2240
_throwInternal ();
2234
2241
}
2235
- streamReadConstraints () .validateFPLength (text .length ());
2242
+ _streamReadConstraints .validateFPLength (text .length ());
2236
2243
_numberBigDecimal = NumberInput .parseBigDecimal (
2237
2244
text , isEnabled (StreamReadFeature .USE_FAST_BIG_NUMBER_PARSER ));
2238
2245
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
@@ -3655,7 +3662,7 @@ protected boolean loadMore() throws IOException
3655
3662
{
3656
3663
if (_inputStream != null ) {
3657
3664
_currInputProcessed += _inputEnd ;
3658
-
3665
+ _streamReadConstraints . validateDocumentLength ( _currInputProcessed );
3659
3666
int count = _inputStream .read (_inputBuffer , 0 , _inputBuffer .length );
3660
3667
if (count > 0 ) {
3661
3668
_inputPtr = 0 ;
@@ -3697,6 +3704,7 @@ protected final void _loadToHaveAtLeast(int minAvailable) throws IOException
3697
3704
}
3698
3705
// Needs to be done here, as per [dataformats-binary#178]
3699
3706
_currInputProcessed += _inputPtr ;
3707
+ _streamReadConstraints .validateDocumentLength (_currInputProcessed );
3700
3708
_inputPtr = 0 ;
3701
3709
while (_inputEnd < minAvailable ) {
3702
3710
int count = _inputStream .read (_inputBuffer , _inputEnd , _inputBuffer .length - _inputEnd );
@@ -3731,6 +3739,7 @@ protected final boolean _tryToLoadToHaveAtLeast(int minAvailable) throws IOExcep
3731
3739
}
3732
3740
// Needs to be done here, as per [dataformats-binary#178]
3733
3741
_currInputProcessed += _inputPtr ;
3742
+ _streamReadConstraints .validateDocumentLength (_currInputProcessed );
3734
3743
_inputPtr = 0 ;
3735
3744
while (_inputEnd < minAvailable ) {
3736
3745
int count = _inputStream .read (_inputBuffer , _inputEnd , _inputBuffer .length - _inputEnd );
@@ -3906,11 +3915,11 @@ private final BigInteger _bigNegative(long l) {
3906
3915
3907
3916
private void createChildArrayContext (final int len ) throws IOException {
3908
3917
_streamReadContext = _streamReadContext .createChildArrayContext (len );
3909
- streamReadConstraints () .validateNestingDepth (_streamReadContext .getNestingDepth ());
3918
+ _streamReadConstraints .validateNestingDepth (_streamReadContext .getNestingDepth ());
3910
3919
}
3911
3920
3912
3921
private void createChildObjectContext (final int len ) throws IOException {
3913
3922
_streamReadContext = _streamReadContext .createChildObjectContext (len );
3914
- streamReadConstraints () .validateNestingDepth (_streamReadContext .getNestingDepth ());
3923
+ _streamReadConstraints .validateNestingDepth (_streamReadContext .getNestingDepth ());
3915
3924
}
3916
3925
}
0 commit comments