From 4cd853c9b3dc05cc44ef2c8d0a261f77729af92f Mon Sep 17 00:00:00 2001 From: Florent Vilmart Date: Mon, 2 Jan 2017 20:07:53 -0500 Subject: [PATCH] Safely inspect bundles --- .../PFObjectSubclassingController.m | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Parse/Internal/Object/Subclassing/PFObjectSubclassingController.m b/Parse/Internal/Object/Subclassing/PFObjectSubclassingController.m index ec6fb137e..0442f71af 100644 --- a/Parse/Internal/Object/Subclassing/PFObjectSubclassingController.m +++ b/Parse/Internal/Object/Subclassing/PFObjectSubclassingController.m @@ -128,20 +128,12 @@ - (void)scanForUnregisteredSubclasses:(BOOL)shouldSubscribe { queue:nil usingBlock:^(NSNotification *note) { @strongify(self); - [self _registerSubclassesInBundle:note.object]; + [self _registerSubclassesInLoadedBundle:note.object]; }]; } NSArray *bundles = [[NSBundle allFrameworks] arrayByAddingObjectsFromArray:[NSBundle allBundles]]; for (NSBundle *bundle in bundles) { - // Skip bundles that aren't loaded yet. - if (!bundle.loaded || !bundle.executablePath) { - continue; - } - // Filter out any system bundles - if ([bundle.bundlePath hasPrefix:@"/System/"] || [bundle.bundlePath hasPrefix:@"/Library/"]) { - continue; - } - [self _registerSubclassesInBundle:bundle]; + [self _registerSubclassesInLoadedBundle:bundle]; } } @@ -338,6 +330,18 @@ - (void)_rawRegisterSubclass:(Class)kls { _registeredSubclasses[[kls parseClassName]] = subclassInfo; } +- (void)_registerSubclassesInLoadedBundle:(NSBundle *)bundle { + // Skip bundles that aren't loaded yet. + if (!bundle.loaded || !bundle.executablePath) { + return; + } + // Filter out any system bundles + if ([bundle.bundlePath hasPrefix:@"/System/"] || [bundle.bundlePath hasPrefix:@"/Library/"] || [bundle.bundlePath rangeOfString:@"iPhoneSimulator.sdk"].location != NSNotFound) { + return; + } + [self _registerSubclassesInBundle:bundle]; +} + - (void)_registerSubclassesInBundle:(NSBundle *)bundle { PFConsistencyAssert(bundle.loaded, @"Cannot register subclasses in a bundle that hasn't been loaded!");