Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when converting some ISO8601 date strings #532

Closed
bonebox opened this issue Sep 12, 2018 · 6 comments
Closed

Crash when converting some ISO8601 date strings #532

bonebox opened this issue Sep 12, 2018 · 6 comments

Comments

@bonebox
Copy link

bonebox commented Sep 12, 2018

After updating to 5.0.0 (from 4.0.3) my app started crashing with the below stack trace. I traced it back to Sync when it attempts to convert an ISO8601 date string that has a 2 decimal place millisecond precision, ie. 2017-12-22T18:10:14.07Z. If the string has a 3 decimal place millisecond precision it works as intended, ie. 2017-12-22T17:51:01.104Z.

2018-09-12 14:45:26.400201-0500 AllogyTest[29108:537888] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSTaggedPointerString substringToIndex:]: Index 6 out of bounds; string length 3'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000113ed61e6 __exceptionPreprocess + 294
	1   libobjc.A.dylib                     0x0000000113573031 objc_exception_throw + 48
	2   CoreFoundation                      0x0000000113f4b975 +[NSException raise:format:] + 197
	3   Foundation                          0x0000000112f6592d -[NSString substringToIndex:] + 118
	4   Sync                                0x000000011089514b +[NSDate(PropertyMapper) dateFromISO8601String:] + 2923
	5   Sync                                0x0000000110894545 +[NSDate(PropertyMapper) dateFromDateString:] + 133
	6   Sync                                0x00000001108985e2 -[NSManagedObject(PropertyMapperHelpers) valueForAttributeDescription:usingRemoteValue:] + 2034
	7   Sync                                0x0000000110899e9b -[NSManagedObject(PropertyMapper) hyp_setDictionaryValue:forKey:attributeDescription:] + 235
	8   Sync                                0x0000000110899c9d -[NSManagedObject(PropertyMapper) hyp_fillWithDictionary:] + 1661
	9   Sync                                0x00000001108b5173 _T0So15NSManagedObjectC4SyncE9sync_fillys10DictionaryVySSypG4with_ABSg6parentSo25NSRelationshipDescriptionCSg0H12RelationshipSo0aB7ContextC7contextA2CC16OperationOptionsV10operationsSbycSg19shouldContinueBlockA2GcSg15objectJSONBlocktF + 259
	10  Sync                                0x00000001108e2af9 _T04SyncAAC7changesySays10DictionaryVySSypGG_SS13inEntityNamedSo11NSPredicateCSg9predicateSo15NSManagedObjectCSg6parentSo25NSRelationshipDescriptionCSg0K12RelationshipSo0iJ7ContextC0dO0AB16OperationOptionsV10operationsSbycSg19shouldContinueBlockA2FcSg15objectJSONBlocktKFZyAF_ANtcfU0_ + 473
	11  Sync                                0x00000001108e2c42 _T04SyncAAC7changesySays10DictionaryVySSypGG_SS13inEntityNamedSo11NSPredicateCSg9predicateSo15NSManagedObjectCSg6parentSo25NSRelationshipDescriptionCSg0K12RelationshipSo0iJ7ContextC0dO0AB16OperationOptionsV10operationsSbycSg19shouldContinueBlockA2FcSg15objectJSONBlocktKFZyAF_ANtcfU0_TA + 66
	12  Sync                                0x000000011089ed2f _T04Sync10DataFilterC7changesySays10DictionaryVySSypGG_SS13inEntityNamedSo11NSPredicateCSg9predicateAC9OperationV10operationsSS15localPrimaryKeySS06remotenO0So22NSManagedObjectContextC7contextyAGc8insertedyAG_So0qR0Ctc7updatedtFZ + 6735
	13  Sync                                0x00000001108e1c97 _T04SyncAAC7changesySays10DictionaryVySSypGG_SS13inEntityNamedSo11NSPredicateCSg9predicateSo15NSManagedObjectCSg6parentSo25NSRelationshipDescriptionCSg0K12RelationshipSo0iJ7ContextC0dO0AB16OperationOptionsV10operationsSbycSg19shouldContinueBlockA2FcSg15objectJSONBlocktKFZ + 3399
	14  Sync                                0x00000001108d44aa _T04SyncAAC7changesySays10DictionaryVySSypGG_SS13inEntityNamedSo11NSPredicateCSg9predicateSo15NSManagedObjectCSg6parentSo25NSRelationshipDescriptionCSg0K12RelationshipSo0iJ7ContextC0dO0AB16OperationOptionsV10operationsySo7NSErrorCSgcSg10completiontFZ + 938
	15  Sync                                0x00000001108cf7f3 _T04SyncAAC7changesySays10DictionaryVySSypGG_SS13inEntityNamedSo11NSPredicateCSg9predicateAA9DataStackC04dataJ0AB16OperationOptionsV10operationsySo7NSErrorCSgcSg10completiontFZySo22NSManagedObjectContextCcfU_ + 339
	16  Sync                                0x00000001108cf8d6 _T04SyncAAC7changesySays10DictionaryVySSypGG_SS13inEntityNamedSo11NSPredicateCSg9predicateAA9DataStackC04dataJ0AB16OperationOptionsV10operationsySo7NSErrorCSgcSg10completiontFZySo22NSManagedObjectContextCcfU_TA + 70
	17  Sync                                0x00000001108aac5c _T04Sync9DataStackC29performInNewBackgroundContextyySo015NSManagedObjectH0CcFyycfU_ + 60
	18  Sync                                0x00000001108af5d5 _T04Sync9DataStackC29performInNewBackgroundContextyySo015NSManagedObjectH0CcFyycfU_TA + 21
	19  Sync                                0x00000001108aac9d _T0Ieg_IeyB_TR + 45
	20  CoreData                            0x000000011d02d4e1 developerSubmittedBlockToNSManagedObjectContextPerform + 161
	21  libdispatch.dylib                   0x0000000114e5f7ec _dispatch_client_callout + 8
	22  libdispatch.dylib                   0x0000000114e67be5 _dispatch_queue_serial_drain + 1305
	23  libdispatch.dylib                   0x0000000114e684fa _dispatch_queue_invoke + 328
	24  libdispatch.dylib                   0x0000000114e64344 _dispatch_queue_override_invoke + 726
	25  libdispatch.dylib                   0x0000000114e6b36c _dispatch_root_queue_drain + 664
	26  libdispatch.dylib                   0x0000000114e6b076 _dispatch_worker_thread3 + 132
	27  libsystem_pthread.dylib             0x000000011538a169 _pthread_wqthread + 1387
	28  libsystem_pthread.dylib             0x0000000115389be9 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
@3lvis
Copy link
Owner

3lvis commented Sep 13, 2018

Thanks for reporting this @bonebox, the issue seems to be connected to 8ee8678

@3lvis
Copy link
Owner

3lvis commented Sep 13, 2018

Hi @bonebox! Delivered a fix in master, let me know if it helps :)

@bonebox
Copy link
Author

bonebox commented Sep 14, 2018

Hey @3lvis! Thanks for the quick fix! That does indeed fix dates with 2 millisecond precision. Apparently some dates from our server also have only 1 decimal place for milliseconds (ie. 2017-11-02T17:27:52.2Z) and that is still crashing. I just realized that after testing this or would have also mentioned it, sorry! Not sure if you want to handle that possibility as well. Fortunately these dates are coming from a service my team controls so I have a ticket open to enforce the 3 digit length for milliseconds.

@3lvis
Copy link
Owner

3lvis commented Sep 17, 2018

@bonebox Wasn't hard to add support for your other dates requirements so I just went for doing that :) #536


Like Sync? Don't forget to support this and other projects in Patreon!

@bonebox
Copy link
Author

bonebox commented Sep 17, 2018

Cool, thanks @3lvis! It appears from this that there is no restriction on decimal length, so probably good to have those supported anyway:

There is no limit on the number of decimal places for the decimal fraction. However, the number of decimal places needs to be agreed to by the communicating parties. For example, in Microsoft SQL Server, the precision of a decimal fraction is 3, i.e., "yyyy-mm-ddThh:mm:ss[.mmm]".

Any idea when the next version will be released with these updates? Thanks!

@3lvis
Copy link
Owner

3lvis commented Sep 17, 2018

@bonebox Shipped! https://github.com/3lvis/Sync/releases/tag/5.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants