Skip to content

Commit 3487af1

Browse files
committed
One minor change needed for FasterXML#185
1 parent 3fc5bb0 commit 3487af1

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java

+40-9
Original file line numberDiff line numberDiff line change
@@ -937,16 +937,14 @@ protected final boolean _checkNextIsIntInArray(final String typeDesc) throws IOE
937937
int ch = _inputBuffer[_inputPtr++];
938938
int type = (ch >> 5) & 0x7;
939939

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)
942942
int tagValue = -1;
943943
if (type == 6) {
944944
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;
950948
}
951949
ch = _inputBuffer[_inputPtr++];
952950
type = (ch >> 5) & 0x7;
@@ -1064,9 +1062,42 @@ protected final boolean _checkNextIsIntInArray(final String typeDesc) throws IOE
10641062

10651063
protected final boolean _checkNextIsEndArray() throws IOException
10661064
{
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
10681099
}
1069-
1100+
10701101
// base impl is fine:
10711102
//public String getCurrentName() throws IOException
10721103

0 commit comments

Comments
 (0)