Skip to content

Commit 4b4b33c

Browse files
committed
Fix #202
1 parent 8b5e2f5 commit 4b4b33c

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/ProtobufParser.java

+15-12
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ private boolean _checkEnd() throws IOException
699699
private JsonToken _handleRootKey(int tag) throws IOException
700700
{
701701
int wireType = (tag & 0x7);
702-
int id = (tag >> 3);
702+
final int id = (tag >> 3);
703703

704704
ProtobufField f;
705705
if (_currentField != null) {
@@ -997,11 +997,11 @@ public boolean nextFieldName(SerializableString sstr) throws IOException
997997
return false;
998998
}
999999
}
1000-
int tag = _decodeVInt();
1000+
final int tag = _decodeVInt();
10011001
// inlined _handleRootKey()
10021002

1003-
int wireType = (tag & 0x7);
1004-
int id = (tag >> 3);
1003+
final int wireType = (tag & 0x7);
1004+
final int id = (tag >> 3);
10051005

10061006
ProtobufField f = _findField(id);
10071007
if (f == null) {
@@ -1033,11 +1033,11 @@ public boolean nextFieldName(SerializableString sstr) throws IOException
10331033
_currToken = JsonToken.END_OBJECT;
10341034
return false;
10351035
}
1036-
int tag = _decodeVInt();
1036+
final int tag = _decodeVInt();
10371037
// inlined '_handleNestedKey()'
10381038

1039-
int wireType = (tag & 0x7);
1040-
int id = (tag >> 3);
1039+
final int wireType = (tag & 0x7);
1040+
final int id = (tag >> 3);
10411041

10421042
ProtobufField f = _findField(id);
10431043
if (f == null) {
@@ -1078,18 +1078,20 @@ public String nextFieldName() throws IOException
10781078
return null;
10791079
}
10801080
}
1081-
int tag = _decodeVInt();
1081+
final int tag = _decodeVInt();
10821082
// inlined _handleRootKey()
10831083

10841084
int wireType = (tag & 0x7);
1085-
int id = (tag >> 3);
1085+
final int id = (tag >> 3);
10861086

10871087
ProtobufField f = _findField(id);
10881088
if (f == null) {
10891089
if (_skipUnknownField(id, wireType) != JsonToken.FIELD_NAME) {
10901090
return null;
10911091
}
10921092
// sub-optimal as skip method already set it, but:
1093+
// [dataformats-binary#202]: need to reset after skipping
1094+
wireType = _currentField.wireType;
10931095
}
10941096
String name = _currentField.name;
10951097
_parsingContext.setCurrentName(name);
@@ -1115,18 +1117,20 @@ public String nextFieldName() throws IOException
11151117
_currToken = JsonToken.END_OBJECT;
11161118
return null;
11171119
}
1118-
int tag = _decodeVInt();
1120+
final int tag = _decodeVInt();
11191121
// inlined '_handleNestedKey()'
11201122

11211123
int wireType = (tag & 0x7);
1122-
int id = (tag >> 3);
1124+
final int id = (tag >> 3);
11231125

11241126
ProtobufField f = _findField(id);
11251127
if (f == null) {
11261128
if (_skipUnknownField(id, wireType) != JsonToken.FIELD_NAME) {
11271129
return null;
11281130
}
11291131
// sub-optimal as skip method already set it, but:
1132+
// [dataformats-binary#202]: need to reset after skipping
1133+
wireType = _currentField.wireType;
11301134
}
11311135
final String name = _currentField.name;
11321136
_parsingContext.setCurrentName(name);
@@ -2111,7 +2115,6 @@ protected ByteArrayBuilder _getByteArrayBuilder() {
21112115
return _byteArrayBuilder;
21122116
}
21132117

2114-
@SuppressWarnings("deprecation")
21152118
protected void _closeInput() throws IOException {
21162119
if (_inputStream != null) {
21172120
if (_ioContext.isResourceManaged() || isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE)) {
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.dataformat.protobuf.failing;
1+
package com.fasterxml.jackson.dataformat.protobuf;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.fasterxml.jackson.core.JsonParser;
@@ -123,7 +123,6 @@ public void testV1toV0() throws Exception {
123123
TestMessageV0 messageV0 = MAPPER
124124
.readerFor(TestMessageV0.class)
125125
.with(schemaV0)
126-
.with(JsonParser.Feature.IGNORE_UNDEFINED)
127126
.readValue(protobufData);
128127

129128
assertEquals(messageV1.getId(), messageV0.getId());

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Project: jackson-datatypes-binaryModules:
88
=== Releases ===
99
------------------------------------------------------------------------
1010

11+
2.10.4 (not yet released)
12+
13+
#202: Parsing a protobuf message doesn't properly skip unknown fields
14+
(reported by dmitry-timin@github)
15+
1116
2.10.3 (03-Mar-2020)
1217

1318
No changes since 2.10.2

0 commit comments

Comments
 (0)