diff --git a/src/common/cocoa_tools.mm b/src/common/cocoa_tools.mm index 53a3a83f1..ed6ef54e3 100644 --- a/src/common/cocoa_tools.mm +++ b/src/common/cocoa_tools.mm @@ -83,7 +83,16 @@ std::optional CocoaTools::GetBundlePath() std::optional ret; @autoreleasepool { - NSURL* url = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; + NSBundle* bundle = [NSBundle mainBundle]; + if (!bundle) + return std::nullopt; + + // A real macOS application bundle should have CFBundlePackageType = APPL. + NSString* packageType = [bundle objectForInfoDictionaryKey:@"CFBundlePackageType"]; + if (![packageType isEqualToString:@"APPL"]) + return std::nullopt; + + NSURL* url = [bundle bundleURL]; if (url) ret = std::string([url fileSystemRepresentation]); }