Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: third_party/protobuf/objectivec/GPBCodedInputStream.m

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 18 matching lines...) Expand all
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 #import "GPBCodedInputStream_PackagePrivate.h" 31 #import "GPBCodedInputStream_PackagePrivate.h"
32 32
33 #import "GPBDictionary_PackagePrivate.h" 33 #import "GPBDictionary_PackagePrivate.h"
34 #import "GPBMessage_PackagePrivate.h" 34 #import "GPBMessage_PackagePrivate.h"
35 #import "GPBUnknownFieldSet_PackagePrivate.h" 35 #import "GPBUnknownFieldSet_PackagePrivate.h"
36 #import "GPBUtilities_PackagePrivate.h" 36 #import "GPBUtilities_PackagePrivate.h"
37 #import "GPBWireFormat.h" 37 #import "GPBWireFormat.h"
38 38
39 NSString *const GPBCodedInputStreamException =
40 GPBNSStringifySymbol(GPBCodedInputStreamException);
41
42 NSString *const GPBCodedInputStreamUnderlyingErrorKey =
43 GPBNSStringifySymbol(GPBCodedInputStreamUnderlyingErrorKey);
44
45 NSString *const GPBCodedInputStreamErrorDomain =
46 GPBNSStringifySymbol(GPBCodedInputStreamErrorDomain);
47
39 static const NSUInteger kDefaultRecursionLimit = 64; 48 static const NSUInteger kDefaultRecursionLimit = 64;
40 49
50 static void RaiseException(NSInteger code, NSString *reason) {
51 NSDictionary *errorInfo = nil;
52 if ([reason length]) {
53 errorInfo = @{ GPBErrorReasonKey: reason };
54 }
55 NSError *error = [NSError errorWithDomain:GPBCodedInputStreamErrorDomain
56 code:code
57 userInfo:errorInfo];
58
59 NSDictionary *exceptionInfo =
60 @{ GPBCodedInputStreamUnderlyingErrorKey: error };
61 [[[NSException alloc] initWithName:GPBCodedInputStreamException
62 reason:reason
63 userInfo:exceptionInfo] raise];
64 }
65
41 static void CheckSize(GPBCodedInputStreamState *state, size_t size) { 66 static void CheckSize(GPBCodedInputStreamState *state, size_t size) {
42 size_t newSize = state->bufferPos + size; 67 size_t newSize = state->bufferPos + size;
43 if (newSize > state->bufferSize) { 68 if (newSize > state->bufferSize) {
44 [NSException raise:NSParseErrorException format:@""]; 69 RaiseException(GPBCodedInputStreamErrorInvalidSize, nil);
45 } 70 }
46 if (newSize > state->currentLimit) { 71 if (newSize > state->currentLimit) {
47 // Fast forward to end of currentLimit; 72 // Fast forward to end of currentLimit;
48 state->bufferPos = state->currentLimit; 73 state->bufferPos = state->currentLimit;
49 [NSException raise:NSParseErrorException format:@""]; 74 RaiseException(GPBCodedInputStreamErrorSubsectionLimitReached, nil);
50 } 75 }
51 } 76 }
52 77
53 static int8_t ReadRawByte(GPBCodedInputStreamState *state) { 78 static int8_t ReadRawByte(GPBCodedInputStreamState *state) {
54 CheckSize(state, sizeof(int8_t)); 79 CheckSize(state, sizeof(int8_t));
55 return ((int8_t *)state->bytes)[state->bufferPos++]; 80 return ((int8_t *)state->bytes)[state->bufferPos++];
56 } 81 }
57 82
58 static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) { 83 static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
59 CheckSize(state, sizeof(int32_t)); 84 CheckSize(state, sizeof(int32_t));
(...skipping 28 matching lines...) Expand all
88 } else { 113 } else {
89 result |= (tmp & 0x7f) << 21; 114 result |= (tmp & 0x7f) << 21;
90 result |= (tmp = ReadRawByte(state)) << 28; 115 result |= (tmp = ReadRawByte(state)) << 28;
91 if (tmp < 0) { 116 if (tmp < 0) {
92 // Discard upper 32 bits. 117 // Discard upper 32 bits.
93 for (int i = 0; i < 5; i++) { 118 for (int i = 0; i < 5; i++) {
94 if (ReadRawByte(state) >= 0) { 119 if (ReadRawByte(state) >= 0) {
95 return result; 120 return result;
96 } 121 }
97 } 122 }
98 [NSException raise:NSParseErrorException 123 RaiseException(GPBCodedInputStreamErrorInvalidVarInt,
99 format:@"Unable to read varint32"]; 124 @"Invalid VarInt32");
100 } 125 }
101 } 126 }
102 } 127 }
103 } 128 }
104 return result; 129 return result;
105 } 130 }
106 131
107 static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) { 132 static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
108 int32_t shift = 0; 133 int32_t shift = 0;
109 int64_t result = 0; 134 int64_t result = 0;
110 while (shift < 64) { 135 while (shift < 64) {
111 int8_t b = ReadRawByte(state); 136 int8_t b = ReadRawByte(state);
112 result |= (int64_t)(b & 0x7F) << shift; 137 result |= (int64_t)(b & 0x7F) << shift;
113 if ((b & 0x80) == 0) { 138 if ((b & 0x80) == 0) {
114 return result; 139 return result;
115 } 140 }
116 shift += 7; 141 shift += 7;
117 } 142 }
118 [NSException raise:NSParseErrorException format:@"Unable to read varint64"]; 143 RaiseException(GPBCodedInputStreamErrorInvalidVarInt, @"Invalid VarInt64");
119 return 0; 144 return 0;
120 } 145 }
121 146
122 static void SkipRawData(GPBCodedInputStreamState *state, size_t size) { 147 static void SkipRawData(GPBCodedInputStreamState *state, size_t size) {
123 CheckSize(state, size); 148 CheckSize(state, size);
124 state->bufferPos += size; 149 state->bufferPos += size;
125 } 150 }
126 151
127 double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state) { 152 double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state) {
128 int64_t value = ReadRawLittleEndian64(state); 153 int64_t value = ReadRawLittleEndian64(state);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 220
196 int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) { 221 int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
197 if (GPBCodedInputStreamIsAtEnd(state)) { 222 if (GPBCodedInputStreamIsAtEnd(state)) {
198 state->lastTag = 0; 223 state->lastTag = 0;
199 return 0; 224 return 0;
200 } 225 }
201 226
202 state->lastTag = ReadRawVarint32(state); 227 state->lastTag = ReadRawVarint32(state);
203 if (state->lastTag == 0) { 228 if (state->lastTag == 0) {
204 // If we actually read zero, that's not a valid tag. 229 // If we actually read zero, that's not a valid tag.
205 [NSException raise:NSParseErrorException 230 RaiseException(GPBCodedInputStreamErrorInvalidTag,
206 format:@"Invalid last tag %d", state->lastTag]; 231 @"A zero tag on the wire is invalid.");
232 }
233 // Tags have to include a valid wireformat, check that also.
234 if (!GPBWireFormatIsValidTag(state->lastTag)) {
235 RaiseException(GPBCodedInputStreamErrorInvalidTag,
236 @"Invalid wireformat in tag.");
207 } 237 }
208 return state->lastTag; 238 return state->lastTag;
209 } 239 }
210 240
211 NSString *GPBCodedInputStreamReadRetainedString( 241 NSString *GPBCodedInputStreamReadRetainedString(
212 GPBCodedInputStreamState *state) { 242 GPBCodedInputStreamState *state) {
213 int32_t size = ReadRawVarint32(state); 243 int32_t size = ReadRawVarint32(state);
214 NSString *result; 244 NSString *result;
215 if (size == 0) { 245 if (size == 0) {
216 result = @""; 246 result = @"";
217 } else { 247 } else {
218 CheckSize(state, size); 248 CheckSize(state, size);
219 result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos] 249 result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
220 length:size 250 length:size
221 encoding:NSUTF8StringEncoding]; 251 encoding:NSUTF8StringEncoding];
222 state->bufferPos += size; 252 state->bufferPos += size;
223 if (!result) { 253 if (!result) {
224 #ifdef DEBUG 254 #ifdef DEBUG
225 // https://developers.google.com/protocol-buffers/docs/proto#scalar 255 // https://developers.google.com/protocol-buffers/docs/proto#scalar
226 NSLog(@"UTF-8 failure, is some field type 'string' when it should be " 256 NSLog(@"UTF-8 failure, is some field type 'string' when it should be "
227 @"'bytes'?"); 257 @"'bytes'?");
228 #endif 258 #endif
229 [NSException raise:NSParseErrorException 259 RaiseException(GPBCodedInputStreamErrorInvalidUTF8, nil);
230 format:@"Invalid UTF-8 for a 'string'"];
231 } 260 }
232 } 261 }
233 return result; 262 return result;
234 } 263 }
235 264
236 NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) { 265 NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) {
237 int32_t size = ReadRawVarint32(state); 266 int32_t size = ReadRawVarint32(state);
238 if (size < 0) return nil; 267 if (size < 0) return nil;
239 CheckSize(state, size); 268 CheckSize(state, size);
240 NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos 269 NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos
(...skipping 14 matching lines...) Expand all
255 freeWhenDone:NO]; 284 freeWhenDone:NO];
256 state->bufferPos += size; 285 state->bufferPos += size;
257 return result; 286 return result;
258 } 287 }
259 288
260 size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, 289 size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
261 size_t byteLimit) { 290 size_t byteLimit) {
262 byteLimit += state->bufferPos; 291 byteLimit += state->bufferPos;
263 size_t oldLimit = state->currentLimit; 292 size_t oldLimit = state->currentLimit;
264 if (byteLimit > oldLimit) { 293 if (byteLimit > oldLimit) {
265 [NSException raise:NSInvalidArgumentException 294 RaiseException(GPBCodedInputStreamErrorInvalidSubsectionLimit, nil);
266 format:@"byteLimit > oldLimit: %tu > %tu", byteLimit, oldLimit];
267 } 295 }
268 state->currentLimit = byteLimit; 296 state->currentLimit = byteLimit;
269 return oldLimit; 297 return oldLimit;
270 } 298 }
271 299
272 void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, 300 void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state,
273 size_t oldLimit) { 301 size_t oldLimit) {
274 state->currentLimit = oldLimit; 302 state->currentLimit = oldLimit;
275 } 303 }
276 304
277 size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state) { 305 size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state) {
278 return state->currentLimit - state->bufferPos; 306 return state->currentLimit - state->bufferPos;
279 } 307 }
280 308
281 BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state) { 309 BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state) {
282 return (state->bufferPos == state->bufferSize) || 310 return (state->bufferPos == state->bufferSize) ||
283 (state->bufferPos == state->currentLimit); 311 (state->bufferPos == state->currentLimit);
284 } 312 }
285 313
286 void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, 314 void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
287 int32_t value) { 315 int32_t value) {
288 if (state->lastTag != value) { 316 if (state->lastTag != value) {
289 [NSException raise:NSParseErrorException 317 RaiseException(GPBCodedInputStreamErrorInvalidTag, @"Unexpected tag read");
290 format:@"Last tag: %d should be %d", state->lastTag, value];
291 } 318 }
292 } 319 }
293 320
294 @implementation GPBCodedInputStream 321 @implementation GPBCodedInputStream
295 322
296 + (instancetype)streamWithData:(NSData *)data { 323 + (instancetype)streamWithData:(NSData *)data {
297 return [[[self alloc] initWithData:data] autorelease]; 324 return [[[self alloc] initWithData:data] autorelease];
298 } 325 }
299 326
300 - (instancetype)initWithData:(NSData *)data { 327 - (instancetype)initWithData:(NSData *)data {
301 if ((self = [super init])) { 328 if ((self = [super init])) {
302 #ifdef DEBUG 329 #ifdef DEBUG
303 NSCAssert([self class] == [GPBCodedInputStream class], 330 NSCAssert([self class] == [GPBCodedInputStream class],
304 @"Subclassing of GPBCodedInputStream is not allowed."); 331 @"Subclassing of GPBCodedInputStream is not allowed.");
305 #endif 332 #endif
306 buffer_ = [data retain]; 333 buffer_ = [data retain];
307 state_.bytes = (const uint8_t *)[data bytes]; 334 state_.bytes = (const uint8_t *)[data bytes];
308 state_.bufferSize = [data length]; 335 state_.bufferSize = [data length];
309 state_.currentLimit = state_.bufferSize; 336 state_.currentLimit = state_.bufferSize;
310 } 337 }
311 return self; 338 return self;
312 } 339 }
313 340
314 - (void)dealloc { 341 - (void)dealloc {
315 [buffer_ release]; 342 [buffer_ release];
316 [super dealloc]; 343 [super dealloc];
317 } 344 }
318 345
346 // Direct access is use for speed, to avoid even internally declaring things
347 // read/write, etc. The warning is enabled in the project to ensure code calling
348 // protos can turn on -Wdirect-ivar-access without issues.
349 #pragma clang diagnostic push
350 #pragma clang diagnostic ignored "-Wdirect-ivar-access"
351
319 - (int32_t)readTag { 352 - (int32_t)readTag {
320 return GPBCodedInputStreamReadTag(&state_); 353 return GPBCodedInputStreamReadTag(&state_);
321 } 354 }
322 355
323 - (void)checkLastTagWas:(int32_t)value { 356 - (void)checkLastTagWas:(int32_t)value {
324 GPBCodedInputStreamCheckLastTagWas(&state_, value); 357 GPBCodedInputStreamCheckLastTagWas(&state_, value);
325 } 358 }
326 359
327 - (BOOL)skipField:(int32_t)tag { 360 - (BOOL)skipField:(int32_t)tag {
361 NSAssert(GPBWireFormatIsValidTag(tag), @"Invalid tag");
328 switch (GPBWireFormatGetTagWireType(tag)) { 362 switch (GPBWireFormatGetTagWireType(tag)) {
329 case GPBWireFormatVarint: 363 case GPBWireFormatVarint:
330 GPBCodedInputStreamReadInt32(&state_); 364 GPBCodedInputStreamReadInt32(&state_);
331 return YES; 365 return YES;
332 case GPBWireFormatFixed64: 366 case GPBWireFormatFixed64:
333 SkipRawData(&state_, sizeof(int64_t)); 367 SkipRawData(&state_, sizeof(int64_t));
334 return YES; 368 return YES;
335 case GPBWireFormatLengthDelimited: 369 case GPBWireFormatLengthDelimited:
336 SkipRawData(&state_, ReadRawVarint32(&state_)); 370 SkipRawData(&state_, ReadRawVarint32(&state_));
337 return YES; 371 return YES;
338 case GPBWireFormatStartGroup: 372 case GPBWireFormatStartGroup:
339 [self skipMessage]; 373 [self skipMessage];
340 GPBCodedInputStreamCheckLastTagWas( 374 GPBCodedInputStreamCheckLastTagWas(
341 &state_, GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag), 375 &state_, GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag),
342 GPBWireFormatEndGroup)); 376 GPBWireFormatEndGroup));
343 return YES; 377 return YES;
344 case GPBWireFormatEndGroup: 378 case GPBWireFormatEndGroup:
345 return NO; 379 return NO;
346 case GPBWireFormatFixed32: 380 case GPBWireFormatFixed32:
347 SkipRawData(&state_, sizeof(int32_t)); 381 SkipRawData(&state_, sizeof(int32_t));
348 return YES; 382 return YES;
349 } 383 }
350 [NSException raise:NSParseErrorException format:@"Invalid tag %d", tag];
351 return NO;
352 } 384 }
353 385
354 - (void)skipMessage { 386 - (void)skipMessage {
355 while (YES) { 387 while (YES) {
356 int32_t tag = GPBCodedInputStreamReadTag(&state_); 388 int32_t tag = GPBCodedInputStreamReadTag(&state_);
357 if (tag == 0 || ![self skipField:tag]) { 389 if (tag == 0 || ![self skipField:tag]) {
358 return; 390 return;
359 } 391 }
360 } 392 }
361 } 393 }
362 394
363 - (BOOL)isAtEnd { 395 - (BOOL)isAtEnd {
364 return GPBCodedInputStreamIsAtEnd(&state_); 396 return GPBCodedInputStreamIsAtEnd(&state_);
365 } 397 }
366 398
367 - (size_t)position { 399 - (size_t)position {
368 return state_.bufferPos; 400 return state_.bufferPos;
369 } 401 }
370 402
403 - (size_t)pushLimit:(size_t)byteLimit {
404 return GPBCodedInputStreamPushLimit(&state_, byteLimit);
405 }
406
407 - (void)popLimit:(size_t)oldLimit {
408 GPBCodedInputStreamPopLimit(&state_, oldLimit);
409 }
410
371 - (double)readDouble { 411 - (double)readDouble {
372 return GPBCodedInputStreamReadDouble(&state_); 412 return GPBCodedInputStreamReadDouble(&state_);
373 } 413 }
374 414
375 - (float)readFloat { 415 - (float)readFloat {
376 return GPBCodedInputStreamReadFloat(&state_); 416 return GPBCodedInputStreamReadFloat(&state_);
377 } 417 }
378 418
379 - (uint64_t)readUInt64 { 419 - (uint64_t)readUInt64 {
380 return GPBCodedInputStreamReadUInt64(&state_); 420 return GPBCodedInputStreamReadUInt64(&state_);
(...skipping 20 matching lines...) Expand all
401 } 441 }
402 442
403 - (NSString *)readString { 443 - (NSString *)readString {
404 return [GPBCodedInputStreamReadRetainedString(&state_) autorelease]; 444 return [GPBCodedInputStreamReadRetainedString(&state_) autorelease];
405 } 445 }
406 446
407 - (void)readGroup:(int32_t)fieldNumber 447 - (void)readGroup:(int32_t)fieldNumber
408 message:(GPBMessage *)message 448 message:(GPBMessage *)message
409 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { 449 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
410 if (state_.recursionDepth >= kDefaultRecursionLimit) { 450 if (state_.recursionDepth >= kDefaultRecursionLimit) {
411 [NSException raise:NSParseErrorException 451 RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
412 format:@"recursionDepth(%tu) >= %tu", state_.recursionDepth,
413 kDefaultRecursionLimit];
414 } 452 }
415 ++state_.recursionDepth; 453 ++state_.recursionDepth;
416 [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry]; 454 [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
417 GPBCodedInputStreamCheckLastTagWas( 455 GPBCodedInputStreamCheckLastTagWas(
418 &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); 456 &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
419 --state_.recursionDepth; 457 --state_.recursionDepth;
420 } 458 }
421 459
422 - (void)readUnknownGroup:(int32_t)fieldNumber 460 - (void)readUnknownGroup:(int32_t)fieldNumber
423 message:(GPBUnknownFieldSet *)message { 461 message:(GPBUnknownFieldSet *)message {
424 if (state_.recursionDepth >= kDefaultRecursionLimit) { 462 if (state_.recursionDepth >= kDefaultRecursionLimit) {
425 [NSException raise:NSParseErrorException 463 RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
426 format:@"recursionDepth(%tu) >= %tu", state_.recursionDepth,
427 kDefaultRecursionLimit];
428 } 464 }
429 ++state_.recursionDepth; 465 ++state_.recursionDepth;
430 [message mergeFromCodedInputStream:self]; 466 [message mergeFromCodedInputStream:self];
431 GPBCodedInputStreamCheckLastTagWas( 467 GPBCodedInputStreamCheckLastTagWas(
432 &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); 468 &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
433 --state_.recursionDepth; 469 --state_.recursionDepth;
434 } 470 }
435 471
436 - (void)readMessage:(GPBMessage *)message 472 - (void)readMessage:(GPBMessage *)message
437 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { 473 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
438 int32_t length = ReadRawVarint32(&state_); 474 int32_t length = ReadRawVarint32(&state_);
439 if (state_.recursionDepth >= kDefaultRecursionLimit) { 475 if (state_.recursionDepth >= kDefaultRecursionLimit) {
440 [NSException raise:NSParseErrorException 476 RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
441 format:@"recursionDepth(%tu) >= %tu", state_.recursionDepth,
442 kDefaultRecursionLimit];
443 } 477 }
444 size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); 478 size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
445 ++state_.recursionDepth; 479 ++state_.recursionDepth;
446 [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry]; 480 [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
447 GPBCodedInputStreamCheckLastTagWas(&state_, 0); 481 GPBCodedInputStreamCheckLastTagWas(&state_, 0);
448 --state_.recursionDepth; 482 --state_.recursionDepth;
449 GPBCodedInputStreamPopLimit(&state_, oldLimit); 483 GPBCodedInputStreamPopLimit(&state_, oldLimit);
450 } 484 }
451 485
452 - (void)readMapEntry:(id)mapDictionary 486 - (void)readMapEntry:(id)mapDictionary
453 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry 487 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
454 field:(GPBFieldDescriptor *)field 488 field:(GPBFieldDescriptor *)field
455 parentMessage:(GPBMessage *)parentMessage { 489 parentMessage:(GPBMessage *)parentMessage {
456 int32_t length = ReadRawVarint32(&state_); 490 int32_t length = ReadRawVarint32(&state_);
457 if (state_.recursionDepth >= kDefaultRecursionLimit) { 491 if (state_.recursionDepth >= kDefaultRecursionLimit) {
458 [NSException raise:NSParseErrorException 492 RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
459 format:@"recursionDepth(%tu) >= %tu", state_.recursionDepth,
460 kDefaultRecursionLimit];
461 } 493 }
462 size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); 494 size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
463 ++state_.recursionDepth; 495 ++state_.recursionDepth;
464 GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field, 496 GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field,
465 parentMessage); 497 parentMessage);
466 GPBCodedInputStreamCheckLastTagWas(&state_, 0); 498 GPBCodedInputStreamCheckLastTagWas(&state_, 0);
467 --state_.recursionDepth; 499 --state_.recursionDepth;
468 GPBCodedInputStreamPopLimit(&state_, oldLimit); 500 GPBCodedInputStreamPopLimit(&state_, oldLimit);
469 } 501 }
470 502
(...skipping 18 matching lines...) Expand all
489 } 521 }
490 522
491 - (int32_t)readSInt32 { 523 - (int32_t)readSInt32 {
492 return GPBCodedInputStreamReadSInt32(&state_); 524 return GPBCodedInputStreamReadSInt32(&state_);
493 } 525 }
494 526
495 - (int64_t)readSInt64 { 527 - (int64_t)readSInt64 {
496 return GPBCodedInputStreamReadSInt64(&state_); 528 return GPBCodedInputStreamReadSInt64(&state_);
497 } 529 }
498 530
531 #pragma clang diagnostic pop
532
499 @end 533 @end
OLDNEW
« no previous file with comments | « third_party/protobuf/objectivec/GPBCodedInputStream.h ('k') | third_party/protobuf/objectivec/GPBCodedOutputStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698