@@ -937,16 +937,14 @@ protected final boolean _checkNextIsIntInArray(final String typeDesc) throws IOE
937
937
int ch = _inputBuffer [_inputPtr ++];
938
938
int type = (ch >> 5 ) & 0x7 ;
939
939
940
- // 01-Nov-2019, tatu: Although we don't use tag for anything, might as well decode it
941
- // for funsies and just ignore.
940
+ // 01-Nov-2019, tatu: We may actually need tag so decode it, but do not assign
941
+ // (that'd override tag we already have)
942
942
int tagValue = -1 ;
943
943
if (type == 6 ) {
944
944
tagValue = _decodeTag (ch & 0x1F );
945
- if (_inputPtr >= _inputEnd ) {
946
- if (!loadMore ()) {
947
- _handleCBOREOF ();
948
- return false ;
949
- }
945
+ if ((_inputPtr >= _inputEnd ) && !loadMore ()) {
946
+ _handleCBOREOF ();
947
+ return false ;
950
948
}
951
949
ch = _inputBuffer [_inputPtr ++];
952
950
type = (ch >> 5 ) & 0x7 ;
@@ -1064,9 +1062,42 @@ protected final boolean _checkNextIsIntInArray(final String typeDesc) throws IOE
1064
1062
1065
1063
protected final boolean _checkNextIsEndArray () throws IOException
1066
1064
{
1067
- return nextToken () == JsonToken .END_ARRAY ;
1065
+ // We know we are in array, with length prefix, and this is where we should be:
1066
+ if (!_parsingContext .expectMoreValues ()) {
1067
+ _tagValue = -1 ;
1068
+ _parsingContext = _parsingContext .getParent ();
1069
+ _currToken = JsonToken .END_ARRAY ;
1070
+ return true ;
1071
+ }
1072
+
1073
+ // But while we otherwise could bail out we should check what follows for better
1074
+ // error reporting... yet we ALSO must avoid direct call to `nextToken()` to avoid
1075
+ // [dataformats-binary#185]
1076
+ int ch = _inputBuffer [_inputPtr ++];
1077
+ int type = (ch >> 5 ) & 0x7 ;
1078
+
1079
+ // No use for tag but removing it is necessary
1080
+ int tagValue = -1 ;
1081
+ if (type == 6 ) {
1082
+ tagValue = _decodeTag (ch & 0x1F );
1083
+ if ((_inputPtr >= _inputEnd ) && !loadMore ()) {
1084
+ _handleCBOREOF ();
1085
+ return false ;
1086
+ }
1087
+ ch = _inputBuffer [_inputPtr ++];
1088
+ type = (ch >> 5 ) & 0x7 ;
1089
+ // including but not limited to nested tags (which we do not allow)
1090
+ if (type == 6 ) {
1091
+ _reportError ("Multiple tags not allowed per value (first tag: " +tagValue +")" );
1092
+ }
1093
+ }
1094
+ // and that's what we need to do for safety; now can drop to generic handling:
1095
+
1096
+ // Important! Need to push back the last byte read (but not consumed)
1097
+ --_inputPtr ;
1098
+ return nextToken () == JsonToken .END_ARRAY ; // should never match
1068
1099
}
1069
-
1100
+
1070
1101
// base impl is fine:
1071
1102
//public String getCurrentName() throws IOException
1072
1103
0 commit comments