diff options
Diffstat (limited to 'objectivec/Tests/GPBMessageTests+Serialization.m')
-rw-r--r-- | objectivec/Tests/GPBMessageTests+Serialization.m | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/objectivec/Tests/GPBMessageTests+Serialization.m b/objectivec/Tests/GPBMessageTests+Serialization.m index 3c861fef..2996f5ff 100644 --- a/objectivec/Tests/GPBMessageTests+Serialization.m +++ b/objectivec/Tests/GPBMessageTests+Serialization.m @@ -946,6 +946,41 @@ static NSData *DataFromCStr(const char *str) { XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidTag); } +- (void)testZeroFieldNum { + // These are ConformanceTestSuite::TestIllegalTags. + + const char *tests[] = { + "\1DEADBEEF", + "\2\1\1", + "\3\4", + "\5DEAD" + }; + + for (size_t i = 0; i < GPBARRAYSIZE(tests); ++i) { + NSData *data = DataFromCStr(tests[i]); + + { + // Message from proto2 syntax file + NSError *error = nil; + Message2 *msg = [Message2 parseFromData:data error:&error]; + XCTAssertNil(msg, @"i = %zd", i); + XCTAssertNotNil(error, @"i = %zd", i); + XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain, @"i = %zd", i); + XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidTag, @"i = %zd", i); + } + + { + // Message from proto3 syntax file + NSError *error = nil; + Message3 *msg = [Message3 parseFromData:data error:&error]; + XCTAssertNil(msg, @"i = %zd", i); + XCTAssertNotNil(error, @"i = %zd", i); + XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain, @"i = %zd", i); + XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidTag, @"i = %zd", i); + } + } +} + - (void)testErrorRecursionDepthReached { NSData *data = DataFromCStr( "\x0A\xF2\x01\x0A\xEF\x01\x0A\xEC\x01\x0A\xE9\x01\x0A\xE6\x01" @@ -1149,22 +1184,27 @@ static NSData *DataFromCStr(const char *str) { [msg.mapInt32Int32 setInt32:101 forKey:2001]; [msg.mapInt64Int64 setInt64:1002 forKey:202]; [msg.mapInt64Int64 setInt64:103 forKey:2003]; + [msg.mapInt64Int64 setInt64:4294967296 forKey:4294967297]; [msg.mapUint32Uint32 setUInt32:1004 forKey:204]; [msg.mapUint32Uint32 setUInt32:105 forKey:2005]; [msg.mapUint64Uint64 setUInt64:1006 forKey:206]; [msg.mapUint64Uint64 setUInt64:107 forKey:2007]; + [msg.mapUint64Uint64 setUInt64:4294967298 forKey:4294967299]; [msg.mapSint32Sint32 setInt32:1008 forKey:208]; [msg.mapSint32Sint32 setInt32:109 forKey:2009]; [msg.mapSint64Sint64 setInt64:1010 forKey:210]; [msg.mapSint64Sint64 setInt64:111 forKey:2011]; + [msg.mapSint64Sint64 setInt64:4294967300 forKey:4294967301]; [msg.mapFixed32Fixed32 setUInt32:1012 forKey:212]; [msg.mapFixed32Fixed32 setUInt32:113 forKey:2013]; [msg.mapFixed64Fixed64 setUInt64:1014 forKey:214]; [msg.mapFixed64Fixed64 setUInt64:115 forKey:2015]; + [msg.mapFixed64Fixed64 setUInt64:4294967302 forKey:4294967303]; [msg.mapSfixed32Sfixed32 setInt32:1016 forKey:216]; [msg.mapSfixed32Sfixed32 setInt32:117 forKey:2017]; [msg.mapSfixed64Sfixed64 setInt64:1018 forKey:218]; [msg.mapSfixed64Sfixed64 setInt64:119 forKey:2019]; + [msg.mapSfixed64Sfixed64 setInt64:4294967304 forKey:4294967305]; [msg.mapInt32Float setFloat:1020.f forKey:220]; [msg.mapInt32Float setFloat:121.f forKey:2021]; [msg.mapInt32Double setDouble:1022. forKey:222]; |