Skip to content

Commit cbaf01a

Browse files
thomasvlcopybara-github
authored andcommitted
[ObjC] Fail for tags with field numbers outside of range.
There is a new conformance test that confirm parse fails if a tag is outside the valid range for a tag/field number. PiperOrigin-RevId: 843674783
1 parent 62b7437 commit cbaf01a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

conformance/failure_list_objc.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# JSON input or output tests are skipped (in conformance_objc.m) as mobile
22
# platforms don't support JSON wire format to avoid code bloat.
33

4-
Required.*.ProtobufInput.BadTag_FieldNumberTooHigh # Should have failed to parse, but didn't.
5-
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
64
Required.*.ProtobufInput.BadTag_OverlongVarint # Should have failed to parse, but didn't.

objectivec/GPBCodedInputStream.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,13 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
206206
return 0;
207207
}
208208

209-
state->lastTag = ReadRawVarint32(state);
209+
uint64_t rawTag = (uint64_t)ReadRawVarint64(state);
210+
state->lastTag = (int32_t)rawTag;
211+
// Following _upb_Decoder_DecodeLongTag logic, fail if this is >32bit value.
212+
if (rawTag > (uint64_t)UINT32_MAX) {
213+
GPBRaiseStreamError(GPBCodedInputStreamErrorInvalidTag, @"Invalid tag");
214+
}
215+
210216
// Tags have to include a valid wireformat.
211217
if (!GPBWireFormatIsValidTag(state->lastTag)) {
212218
GPBRaiseStreamError(GPBCodedInputStreamErrorInvalidTag, @"Invalid wireformat in tag.");

0 commit comments

Comments
 (0)