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.
This commit is contained in:
parent
f3f5b3fb64
commit
c9167f2acd
@ -219,15 +219,16 @@ NSString *GPBCodedInputStreamReadRetainedString(
|
|||||||
result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
|
result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
|
||||||
length:size
|
length:size
|
||||||
encoding:NSUTF8StringEncoding];
|
encoding:NSUTF8StringEncoding];
|
||||||
|
state->bufferPos += size;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
result = @"";
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// https://developers.google.com/protocol-buffers/docs/proto#scalar
|
// 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'?");
|
@"'bytes'?");
|
||||||
#endif
|
#endif
|
||||||
|
[NSException raise:NSParseErrorException
|
||||||
|
format:@"Invalid UTF-8 for a 'string'"];
|
||||||
}
|
}
|
||||||
state->bufferPos += size;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -283,16 +283,15 @@
|
|||||||
[output writeRawData:[NSData dataWithBytes:bytes length:sizeof(bytes)]];
|
[output writeRawData:[NSData dataWithBytes:bytes length:sizeof(bytes)]];
|
||||||
[output flush];
|
[output flush];
|
||||||
|
|
||||||
NSData* data =
|
NSData *data =
|
||||||
[rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
|
[rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
|
||||||
GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
|
GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
|
||||||
|
NSError *error = nil;
|
||||||
TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
|
TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
|
||||||
extensionRegistry:nil
|
extensionRegistry:nil
|
||||||
error:NULL];
|
error:&error];
|
||||||
XCTAssertNotNil(message);
|
XCTAssertNotNil(error);
|
||||||
// Make sure we can read string properties twice without crashing.
|
XCTAssertNil(message);
|
||||||
XCTAssertEqual([message.defaultString length], (NSUInteger)0);
|
|
||||||
XCTAssertEqualObjects(@"", message.defaultString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testBOMWithinStrings {
|
- (void)testBOMWithinStrings {
|
||||||
|
Loading…
Reference in New Issue
Block a user