aboutsummaryrefslogtreecommitdiff
path: root/objectivec/GPBCodedInputStream.m
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2016-04-05 17:04:36 -0400
committerThomas Van Lenten <thomasvl@google.com>2016-04-05 17:16:33 -0400
commitc9167f2acdd8ab477acb620cdd0bd231c8a0f3d0 (patch)
tree2e07a34302b55980b5545c5196958bed09ba9f7c /objectivec/GPBCodedInputStream.m
parentf3f5b3fb64308817c5df105321995c5b9d0c0be7 (diff)
downloadprotobuf-c9167f2acdd8ab477acb620cdd0bd231c8a0f3d0.tar.gz
protobuf-c9167f2acdd8ab477acb620cdd0bd231c8a0f3d0.tar.bz2
protobuf-c9167f2acdd8ab477acb620cdd0bd231c8a0f3d0.zip
Error during parsing for invalid UTF-8 instead of dropping dropping data.
This seems to be some code evolution side effects. Back when there was a custom string class, we couldn't really error when we finally saw the string was bad so we had to return the empty string, but now that full validation is done up front, it can error out.
Diffstat (limited to 'objectivec/GPBCodedInputStream.m')
-rw-r--r--objectivec/GPBCodedInputStream.m7
1 files changed, 4 insertions, 3 deletions
diff --git a/objectivec/GPBCodedInputStream.m b/objectivec/GPBCodedInputStream.m
index eaa28e50..319ec15b 100644
--- a/objectivec/GPBCodedInputStream.m
+++ b/objectivec/GPBCodedInputStream.m
@@ -219,15 +219,16 @@ NSString *GPBCodedInputStreamReadRetainedString(
result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
length:size
encoding:NSUTF8StringEncoding];
+ state->bufferPos += size;
if (!result) {
- result = @"";
#ifdef DEBUG
// https://developers.google.com/protocol-buffers/docs/proto#scalar
- NSLog(@"UTF8 failure, is some field type 'string' when it should be "
+ NSLog(@"UTF-8 failure, is some field type 'string' when it should be "
@"'bytes'?");
#endif
+ [NSException raise:NSParseErrorException
+ format:@"Invalid UTF-8 for a 'string'"];
}
- state->bufferPos += size;
}
return result;
}