OLD | NEW |
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 Loading... |
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 | |
48 static const NSUInteger kDefaultRecursionLimit = 64; | 39 static const NSUInteger kDefaultRecursionLimit = 64; |
49 | 40 |
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 | |
66 static void CheckSize(GPBCodedInputStreamState *state, size_t size) { | 41 static void CheckSize(GPBCodedInputStreamState *state, size_t size) { |
67 size_t newSize = state->bufferPos + size; | 42 size_t newSize = state->bufferPos + size; |
68 if (newSize > state->bufferSize) { | 43 if (newSize > state->bufferSize) { |
69 RaiseException(GPBCodedInputStreamErrorInvalidSize, nil); | 44 [NSException raise:NSParseErrorException format:@""]; |
70 } | 45 } |
71 if (newSize > state->currentLimit) { | 46 if (newSize > state->currentLimit) { |
72 // Fast forward to end of currentLimit; | 47 // Fast forward to end of currentLimit; |
73 state->bufferPos = state->currentLimit; | 48 state->bufferPos = state->currentLimit; |
74 RaiseException(GPBCodedInputStreamErrorSubsectionLimitReached, nil); | 49 [NSException raise:NSParseErrorException format:@""]; |
75 } | 50 } |
76 } | 51 } |
77 | 52 |
78 static int8_t ReadRawByte(GPBCodedInputStreamState *state) { | 53 static int8_t ReadRawByte(GPBCodedInputStreamState *state) { |
79 CheckSize(state, sizeof(int8_t)); | 54 CheckSize(state, sizeof(int8_t)); |
80 return ((int8_t *)state->bytes)[state->bufferPos++]; | 55 return ((int8_t *)state->bytes)[state->bufferPos++]; |
81 } | 56 } |
82 | 57 |
83 static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) { | 58 static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) { |
84 CheckSize(state, sizeof(int32_t)); | 59 CheckSize(state, sizeof(int32_t)); |
(...skipping 28 matching lines...) Expand all Loading... |
113 } else { | 88 } else { |
114 result |= (tmp & 0x7f) << 21; | 89 result |= (tmp & 0x7f) << 21; |
115 result |= (tmp = ReadRawByte(state)) << 28; | 90 result |= (tmp = ReadRawByte(state)) << 28; |
116 if (tmp < 0) { | 91 if (tmp < 0) { |
117 // Discard upper 32 bits. | 92 // Discard upper 32 bits. |
118 for (int i = 0; i < 5; i++) { | 93 for (int i = 0; i < 5; i++) { |
119 if (ReadRawByte(state) >= 0) { | 94 if (ReadRawByte(state) >= 0) { |
120 return result; | 95 return result; |
121 } | 96 } |
122 } | 97 } |
123 RaiseException(GPBCodedInputStreamErrorInvalidVarInt, | 98 [NSException raise:NSParseErrorException |
124 @"Invalid VarInt32"); | 99 format:@"Unable to read varint32"]; |
125 } | 100 } |
126 } | 101 } |
127 } | 102 } |
128 } | 103 } |
129 return result; | 104 return result; |
130 } | 105 } |
131 | 106 |
132 static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) { | 107 static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) { |
133 int32_t shift = 0; | 108 int32_t shift = 0; |
134 int64_t result = 0; | 109 int64_t result = 0; |
135 while (shift < 64) { | 110 while (shift < 64) { |
136 int8_t b = ReadRawByte(state); | 111 int8_t b = ReadRawByte(state); |
137 result |= (int64_t)(b & 0x7F) << shift; | 112 result |= (int64_t)(b & 0x7F) << shift; |
138 if ((b & 0x80) == 0) { | 113 if ((b & 0x80) == 0) { |
139 return result; | 114 return result; |
140 } | 115 } |
141 shift += 7; | 116 shift += 7; |
142 } | 117 } |
143 RaiseException(GPBCodedInputStreamErrorInvalidVarInt, @"Invalid VarInt64"); | 118 [NSException raise:NSParseErrorException format:@"Unable to read varint64"]; |
144 return 0; | 119 return 0; |
145 } | 120 } |
146 | 121 |
147 static void SkipRawData(GPBCodedInputStreamState *state, size_t size) { | 122 static void SkipRawData(GPBCodedInputStreamState *state, size_t size) { |
148 CheckSize(state, size); | 123 CheckSize(state, size); |
149 state->bufferPos += size; | 124 state->bufferPos += size; |
150 } | 125 } |
151 | 126 |
152 double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state) { | 127 double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state) { |
153 int64_t value = ReadRawLittleEndian64(state); | 128 int64_t value = ReadRawLittleEndian64(state); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 195 |
221 int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) { | 196 int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) { |
222 if (GPBCodedInputStreamIsAtEnd(state)) { | 197 if (GPBCodedInputStreamIsAtEnd(state)) { |
223 state->lastTag = 0; | 198 state->lastTag = 0; |
224 return 0; | 199 return 0; |
225 } | 200 } |
226 | 201 |
227 state->lastTag = ReadRawVarint32(state); | 202 state->lastTag = ReadRawVarint32(state); |
228 if (state->lastTag == 0) { | 203 if (state->lastTag == 0) { |
229 // If we actually read zero, that's not a valid tag. | 204 // If we actually read zero, that's not a valid tag. |
230 RaiseException(GPBCodedInputStreamErrorInvalidTag, | 205 [NSException raise:NSParseErrorException |
231 @"A zero tag on the wire is invalid."); | 206 format:@"Invalid last tag %d", state->lastTag]; |
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."); | |
237 } | 207 } |
238 return state->lastTag; | 208 return state->lastTag; |
239 } | 209 } |
240 | 210 |
241 NSString *GPBCodedInputStreamReadRetainedString( | 211 NSString *GPBCodedInputStreamReadRetainedString( |
242 GPBCodedInputStreamState *state) { | 212 GPBCodedInputStreamState *state) { |
243 int32_t size = ReadRawVarint32(state); | 213 int32_t size = ReadRawVarint32(state); |
244 NSString *result; | 214 NSString *result; |
245 if (size == 0) { | 215 if (size == 0) { |
246 result = @""; | 216 result = @""; |
247 } else { | 217 } else { |
248 CheckSize(state, size); | 218 CheckSize(state, size); |
249 result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos] | 219 result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos] |
250 length:size | 220 length:size |
251 encoding:NSUTF8StringEncoding]; | 221 encoding:NSUTF8StringEncoding]; |
252 state->bufferPos += size; | 222 state->bufferPos += size; |
253 if (!result) { | 223 if (!result) { |
254 #ifdef DEBUG | 224 #ifdef DEBUG |
255 // https://developers.google.com/protocol-buffers/docs/proto#scalar | 225 // https://developers.google.com/protocol-buffers/docs/proto#scalar |
256 NSLog(@"UTF-8 failure, is some field type 'string' when it should be " | 226 NSLog(@"UTF-8 failure, is some field type 'string' when it should be " |
257 @"'bytes'?"); | 227 @"'bytes'?"); |
258 #endif | 228 #endif |
259 RaiseException(GPBCodedInputStreamErrorInvalidUTF8, nil); | 229 [NSException raise:NSParseErrorException |
| 230 format:@"Invalid UTF-8 for a 'string'"]; |
260 } | 231 } |
261 } | 232 } |
262 return result; | 233 return result; |
263 } | 234 } |
264 | 235 |
265 NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) { | 236 NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) { |
266 int32_t size = ReadRawVarint32(state); | 237 int32_t size = ReadRawVarint32(state); |
267 if (size < 0) return nil; | 238 if (size < 0) return nil; |
268 CheckSize(state, size); | 239 CheckSize(state, size); |
269 NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos | 240 NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos |
(...skipping 14 matching lines...) Expand all Loading... |
284 freeWhenDone:NO]; | 255 freeWhenDone:NO]; |
285 state->bufferPos += size; | 256 state->bufferPos += size; |
286 return result; | 257 return result; |
287 } | 258 } |
288 | 259 |
289 size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, | 260 size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state, |
290 size_t byteLimit) { | 261 size_t byteLimit) { |
291 byteLimit += state->bufferPos; | 262 byteLimit += state->bufferPos; |
292 size_t oldLimit = state->currentLimit; | 263 size_t oldLimit = state->currentLimit; |
293 if (byteLimit > oldLimit) { | 264 if (byteLimit > oldLimit) { |
294 RaiseException(GPBCodedInputStreamErrorInvalidSubsectionLimit, nil); | 265 [NSException raise:NSInvalidArgumentException |
| 266 format:@"byteLimit > oldLimit: %tu > %tu", byteLimit, oldLimit]; |
295 } | 267 } |
296 state->currentLimit = byteLimit; | 268 state->currentLimit = byteLimit; |
297 return oldLimit; | 269 return oldLimit; |
298 } | 270 } |
299 | 271 |
300 void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, | 272 void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state, |
301 size_t oldLimit) { | 273 size_t oldLimit) { |
302 state->currentLimit = oldLimit; | 274 state->currentLimit = oldLimit; |
303 } | 275 } |
304 | 276 |
305 size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state) { | 277 size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state) { |
306 return state->currentLimit - state->bufferPos; | 278 return state->currentLimit - state->bufferPos; |
307 } | 279 } |
308 | 280 |
309 BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state) { | 281 BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state) { |
310 return (state->bufferPos == state->bufferSize) || | 282 return (state->bufferPos == state->bufferSize) || |
311 (state->bufferPos == state->currentLimit); | 283 (state->bufferPos == state->currentLimit); |
312 } | 284 } |
313 | 285 |
314 void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, | 286 void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state, |
315 int32_t value) { | 287 int32_t value) { |
316 if (state->lastTag != value) { | 288 if (state->lastTag != value) { |
317 RaiseException(GPBCodedInputStreamErrorInvalidTag, @"Unexpected tag read"); | 289 [NSException raise:NSParseErrorException |
| 290 format:@"Last tag: %d should be %d", state->lastTag, value]; |
318 } | 291 } |
319 } | 292 } |
320 | 293 |
321 @implementation GPBCodedInputStream | 294 @implementation GPBCodedInputStream |
322 | 295 |
323 + (instancetype)streamWithData:(NSData *)data { | 296 + (instancetype)streamWithData:(NSData *)data { |
324 return [[[self alloc] initWithData:data] autorelease]; | 297 return [[[self alloc] initWithData:data] autorelease]; |
325 } | 298 } |
326 | 299 |
327 - (instancetype)initWithData:(NSData *)data { | 300 - (instancetype)initWithData:(NSData *)data { |
328 if ((self = [super init])) { | 301 if ((self = [super init])) { |
329 #ifdef DEBUG | 302 #ifdef DEBUG |
330 NSCAssert([self class] == [GPBCodedInputStream class], | 303 NSCAssert([self class] == [GPBCodedInputStream class], |
331 @"Subclassing of GPBCodedInputStream is not allowed."); | 304 @"Subclassing of GPBCodedInputStream is not allowed."); |
332 #endif | 305 #endif |
333 buffer_ = [data retain]; | 306 buffer_ = [data retain]; |
334 state_.bytes = (const uint8_t *)[data bytes]; | 307 state_.bytes = (const uint8_t *)[data bytes]; |
335 state_.bufferSize = [data length]; | 308 state_.bufferSize = [data length]; |
336 state_.currentLimit = state_.bufferSize; | 309 state_.currentLimit = state_.bufferSize; |
337 } | 310 } |
338 return self; | 311 return self; |
339 } | 312 } |
340 | 313 |
341 - (void)dealloc { | 314 - (void)dealloc { |
342 [buffer_ release]; | 315 [buffer_ release]; |
343 [super dealloc]; | 316 [super dealloc]; |
344 } | 317 } |
345 | 318 |
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 | |
352 - (int32_t)readTag { | 319 - (int32_t)readTag { |
353 return GPBCodedInputStreamReadTag(&state_); | 320 return GPBCodedInputStreamReadTag(&state_); |
354 } | 321 } |
355 | 322 |
356 - (void)checkLastTagWas:(int32_t)value { | 323 - (void)checkLastTagWas:(int32_t)value { |
357 GPBCodedInputStreamCheckLastTagWas(&state_, value); | 324 GPBCodedInputStreamCheckLastTagWas(&state_, value); |
358 } | 325 } |
359 | 326 |
360 - (BOOL)skipField:(int32_t)tag { | 327 - (BOOL)skipField:(int32_t)tag { |
361 NSAssert(GPBWireFormatIsValidTag(tag), @"Invalid tag"); | |
362 switch (GPBWireFormatGetTagWireType(tag)) { | 328 switch (GPBWireFormatGetTagWireType(tag)) { |
363 case GPBWireFormatVarint: | 329 case GPBWireFormatVarint: |
364 GPBCodedInputStreamReadInt32(&state_); | 330 GPBCodedInputStreamReadInt32(&state_); |
365 return YES; | 331 return YES; |
366 case GPBWireFormatFixed64: | 332 case GPBWireFormatFixed64: |
367 SkipRawData(&state_, sizeof(int64_t)); | 333 SkipRawData(&state_, sizeof(int64_t)); |
368 return YES; | 334 return YES; |
369 case GPBWireFormatLengthDelimited: | 335 case GPBWireFormatLengthDelimited: |
370 SkipRawData(&state_, ReadRawVarint32(&state_)); | 336 SkipRawData(&state_, ReadRawVarint32(&state_)); |
371 return YES; | 337 return YES; |
372 case GPBWireFormatStartGroup: | 338 case GPBWireFormatStartGroup: |
373 [self skipMessage]; | 339 [self skipMessage]; |
374 GPBCodedInputStreamCheckLastTagWas( | 340 GPBCodedInputStreamCheckLastTagWas( |
375 &state_, GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag), | 341 &state_, GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag), |
376 GPBWireFormatEndGroup)); | 342 GPBWireFormatEndGroup)); |
377 return YES; | 343 return YES; |
378 case GPBWireFormatEndGroup: | 344 case GPBWireFormatEndGroup: |
379 return NO; | 345 return NO; |
380 case GPBWireFormatFixed32: | 346 case GPBWireFormatFixed32: |
381 SkipRawData(&state_, sizeof(int32_t)); | 347 SkipRawData(&state_, sizeof(int32_t)); |
382 return YES; | 348 return YES; |
383 } | 349 } |
| 350 [NSException raise:NSParseErrorException format:@"Invalid tag %d", tag]; |
| 351 return NO; |
384 } | 352 } |
385 | 353 |
386 - (void)skipMessage { | 354 - (void)skipMessage { |
387 while (YES) { | 355 while (YES) { |
388 int32_t tag = GPBCodedInputStreamReadTag(&state_); | 356 int32_t tag = GPBCodedInputStreamReadTag(&state_); |
389 if (tag == 0 || ![self skipField:tag]) { | 357 if (tag == 0 || ![self skipField:tag]) { |
390 return; | 358 return; |
391 } | 359 } |
392 } | 360 } |
393 } | 361 } |
394 | 362 |
395 - (BOOL)isAtEnd { | 363 - (BOOL)isAtEnd { |
396 return GPBCodedInputStreamIsAtEnd(&state_); | 364 return GPBCodedInputStreamIsAtEnd(&state_); |
397 } | 365 } |
398 | 366 |
399 - (size_t)position { | 367 - (size_t)position { |
400 return state_.bufferPos; | 368 return state_.bufferPos; |
401 } | 369 } |
402 | 370 |
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 | |
411 - (double)readDouble { | 371 - (double)readDouble { |
412 return GPBCodedInputStreamReadDouble(&state_); | 372 return GPBCodedInputStreamReadDouble(&state_); |
413 } | 373 } |
414 | 374 |
415 - (float)readFloat { | 375 - (float)readFloat { |
416 return GPBCodedInputStreamReadFloat(&state_); | 376 return GPBCodedInputStreamReadFloat(&state_); |
417 } | 377 } |
418 | 378 |
419 - (uint64_t)readUInt64 { | 379 - (uint64_t)readUInt64 { |
420 return GPBCodedInputStreamReadUInt64(&state_); | 380 return GPBCodedInputStreamReadUInt64(&state_); |
(...skipping 20 matching lines...) Expand all Loading... |
441 } | 401 } |
442 | 402 |
443 - (NSString *)readString { | 403 - (NSString *)readString { |
444 return [GPBCodedInputStreamReadRetainedString(&state_) autorelease]; | 404 return [GPBCodedInputStreamReadRetainedString(&state_) autorelease]; |
445 } | 405 } |
446 | 406 |
447 - (void)readGroup:(int32_t)fieldNumber | 407 - (void)readGroup:(int32_t)fieldNumber |
448 message:(GPBMessage *)message | 408 message:(GPBMessage *)message |
449 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { | 409 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { |
450 if (state_.recursionDepth >= kDefaultRecursionLimit) { | 410 if (state_.recursionDepth >= kDefaultRecursionLimit) { |
451 RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil); | 411 [NSException raise:NSParseErrorException |
| 412 format:@"recursionDepth(%tu) >= %tu", state_.recursionDepth, |
| 413 kDefaultRecursionLimit]; |
452 } | 414 } |
453 ++state_.recursionDepth; | 415 ++state_.recursionDepth; |
454 [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry]; | 416 [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry]; |
455 GPBCodedInputStreamCheckLastTagWas( | 417 GPBCodedInputStreamCheckLastTagWas( |
456 &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); | 418 &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); |
457 --state_.recursionDepth; | 419 --state_.recursionDepth; |
458 } | 420 } |
459 | 421 |
460 - (void)readUnknownGroup:(int32_t)fieldNumber | 422 - (void)readUnknownGroup:(int32_t)fieldNumber |
461 message:(GPBUnknownFieldSet *)message { | 423 message:(GPBUnknownFieldSet *)message { |
462 if (state_.recursionDepth >= kDefaultRecursionLimit) { | 424 if (state_.recursionDepth >= kDefaultRecursionLimit) { |
463 RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil); | 425 [NSException raise:NSParseErrorException |
| 426 format:@"recursionDepth(%tu) >= %tu", state_.recursionDepth, |
| 427 kDefaultRecursionLimit]; |
464 } | 428 } |
465 ++state_.recursionDepth; | 429 ++state_.recursionDepth; |
466 [message mergeFromCodedInputStream:self]; | 430 [message mergeFromCodedInputStream:self]; |
467 GPBCodedInputStreamCheckLastTagWas( | 431 GPBCodedInputStreamCheckLastTagWas( |
468 &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); | 432 &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup)); |
469 --state_.recursionDepth; | 433 --state_.recursionDepth; |
470 } | 434 } |
471 | 435 |
472 - (void)readMessage:(GPBMessage *)message | 436 - (void)readMessage:(GPBMessage *)message |
473 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { | 437 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry { |
474 int32_t length = ReadRawVarint32(&state_); | 438 int32_t length = ReadRawVarint32(&state_); |
475 if (state_.recursionDepth >= kDefaultRecursionLimit) { | 439 if (state_.recursionDepth >= kDefaultRecursionLimit) { |
476 RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil); | 440 [NSException raise:NSParseErrorException |
| 441 format:@"recursionDepth(%tu) >= %tu", state_.recursionDepth, |
| 442 kDefaultRecursionLimit]; |
477 } | 443 } |
478 size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); | 444 size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); |
479 ++state_.recursionDepth; | 445 ++state_.recursionDepth; |
480 [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry]; | 446 [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry]; |
481 GPBCodedInputStreamCheckLastTagWas(&state_, 0); | 447 GPBCodedInputStreamCheckLastTagWas(&state_, 0); |
482 --state_.recursionDepth; | 448 --state_.recursionDepth; |
483 GPBCodedInputStreamPopLimit(&state_, oldLimit); | 449 GPBCodedInputStreamPopLimit(&state_, oldLimit); |
484 } | 450 } |
485 | 451 |
486 - (void)readMapEntry:(id)mapDictionary | 452 - (void)readMapEntry:(id)mapDictionary |
487 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry | 453 extensionRegistry:(GPBExtensionRegistry *)extensionRegistry |
488 field:(GPBFieldDescriptor *)field | 454 field:(GPBFieldDescriptor *)field |
489 parentMessage:(GPBMessage *)parentMessage { | 455 parentMessage:(GPBMessage *)parentMessage { |
490 int32_t length = ReadRawVarint32(&state_); | 456 int32_t length = ReadRawVarint32(&state_); |
491 if (state_.recursionDepth >= kDefaultRecursionLimit) { | 457 if (state_.recursionDepth >= kDefaultRecursionLimit) { |
492 RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil); | 458 [NSException raise:NSParseErrorException |
| 459 format:@"recursionDepth(%tu) >= %tu", state_.recursionDepth, |
| 460 kDefaultRecursionLimit]; |
493 } | 461 } |
494 size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); | 462 size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length); |
495 ++state_.recursionDepth; | 463 ++state_.recursionDepth; |
496 GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field, | 464 GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field, |
497 parentMessage); | 465 parentMessage); |
498 GPBCodedInputStreamCheckLastTagWas(&state_, 0); | 466 GPBCodedInputStreamCheckLastTagWas(&state_, 0); |
499 --state_.recursionDepth; | 467 --state_.recursionDepth; |
500 GPBCodedInputStreamPopLimit(&state_, oldLimit); | 468 GPBCodedInputStreamPopLimit(&state_, oldLimit); |
501 } | 469 } |
502 | 470 |
(...skipping 18 matching lines...) Expand all Loading... |
521 } | 489 } |
522 | 490 |
523 - (int32_t)readSInt32 { | 491 - (int32_t)readSInt32 { |
524 return GPBCodedInputStreamReadSInt32(&state_); | 492 return GPBCodedInputStreamReadSInt32(&state_); |
525 } | 493 } |
526 | 494 |
527 - (int64_t)readSInt64 { | 495 - (int64_t)readSInt64 { |
528 return GPBCodedInputStreamReadSInt64(&state_); | 496 return GPBCodedInputStreamReadSInt64(&state_); |
529 } | 497 } |
530 | 498 |
531 #pragma clang diagnostic pop | |
532 | |
533 @end | 499 @end |
OLD | NEW |