aboutsummaryrefslogtreecommitdiff
path: root/objectivec/GPBMessage.m
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2016-06-29 09:51:13 -0400
committerGitHub <noreply@github.com>2016-06-29 09:51:13 -0400
commitc18aa7795a2e02ef700ff8b039d94ecdcc33432f (patch)
tree6a1c28a6dbfd0ef412c23236d1aa8d4f2c76abe5 /objectivec/GPBMessage.m
parente0016c5b6ae61ad60d260a78c5834cc537b46d10 (diff)
downloadprotobuf-c18aa7795a2e02ef700ff8b039d94ecdcc33432f.tar.gz
protobuf-c18aa7795a2e02ef700ff8b039d94ecdcc33432f.tar.bz2
protobuf-c18aa7795a2e02ef700ff8b039d94ecdcc33432f.zip
Validate the tag numbers when parsing. (#1725)
There was a twist code path (that some times showed up due to what happened to be in memory in failure cases), that would cast a bogus wire type into the enum, and then fall through switch statements. Resolve this by validating all wire types when parsing tags and throwing the error at that point so it can't enter the system. As added safety, stick in a few asserts for apis that get passed tags to ensure they also are only seeing valid data. Bonus: Tweak the parsing loop to skip some work when we get the end marker (zero tag) instead of still looping through all the fields.
Diffstat (limited to 'objectivec/GPBMessage.m')
-rw-r--r--objectivec/GPBMessage.m5
1 files changed, 4 insertions, 1 deletions
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m
index 7ab184c1..b9566bdf 100644
--- a/objectivec/GPBMessage.m
+++ b/objectivec/GPBMessage.m
@@ -2279,6 +2279,9 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
while (YES) {
BOOL merged = NO;
tag = GPBCodedInputStreamReadTag(state);
+ if (tag == 0) {
+ break; // Reached end.
+ }
for (NSUInteger i = 0; i < numFields; ++i) {
if (startingIndex >= numFields) startingIndex = 0;
GPBFieldDescriptor *fieldDescriptor = fields[startingIndex];
@@ -2317,7 +2320,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
}
} // for(i < numFields)
- if (!merged) {
+ if (!merged && (tag != 0)) {
// Primitive, repeated types can be packed on unpacked on the wire, and
// are parsed either way. The above loop covered tag in the preferred
// for, so this need to check the alternate form.