-
Notifications
You must be signed in to change notification settings - Fork 237
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
#278 migration support for database delivered in framework #286
base: master
Are you sure you want to change the base?
Conversation
Feel free to close it if #268 fixes it |
|
||
if (modelBundle == nil) | ||
{ | ||
modelBundle = [NSBundle mainBundle]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the main bundle is fetched and then later added to an array on line 983. However according to Apple documentation on the mainBundle method the method can return nil. Therefore an error will occur when attempting to add nil to an array.
This method may return a valid bundle object even for unbundled apps. It may also return nil if the bundle object could not be created, so always check the return value.
You could add a additional check and error code for this case if you wanted to make this code as resilient as possible.
typedef NS_ENUM(NSInteger, EncryptedStoreError)
{
EncryptedStoreErrorIncorrectPasscode = 6000,
EncryptedStoreErrorMigrationFailed,
EncryptedStoreErrorModelLoadFailed
};
if (modelBundle == nil)
{
if (error)
{
NSDictionary * userInfo = @{EncryptedStoreErrorMessageKey : @"Main Bundle not found, cannot load model"};
*error = [NSError errorWithDomain: EncryptedStoreErrorDomain
code: EncryptedStoreErrorModelLoadFailed
userInfo: userInfo];
}
return NO;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree with you about handling mainBundle method however it is kind of overkill since if mainBundle is nil then we are in more serious troubles than handling error correctly,
Also getting modelBundle from mainBundle assumes that model is delivered inside app while issue which has been fixed by this PR is to migrate correctly model delivered in framework
Anyway feel free to raise separate PR for fixing mainBundle potential nil return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, perhaps it would be an extreme edge case.
No description provided.