From 0fcfdc7c7133ba898b37742834f47319ef000934 Mon Sep 17 00:00:00 2001 From: wwwcg Date: Wed, 30 Oct 2024 20:14:00 +0800 Subject: [PATCH] fix(ios): potential thread race in vfs file module --- framework/ios/base/bridge/HippyBridge.h | 2 +- modules/vfs/ios/HippyFileHandler.h | 4 ++-- modules/vfs/ios/HippyFileHandler.mm | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/framework/ios/base/bridge/HippyBridge.h b/framework/ios/base/bridge/HippyBridge.h index addcc0193e9..0360128a577 100644 --- a/framework/ios/base/bridge/HippyBridge.h +++ b/framework/ios/base/bridge/HippyBridge.h @@ -214,7 +214,7 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass); @property (nonatomic, copy, readonly) NSArray *bundleURLs; /// Path of sandbox directory -@property (nonatomic, strong) NSString *sandboxDirectory; +@property (atomic, copy) NSString *sandboxDirectory; /// Shared data between different rootViews on same bridge. /// Set by HippyRootView when runHippyApplication. diff --git a/modules/vfs/ios/HippyFileHandler.h b/modules/vfs/ios/HippyFileHandler.h index 5d306bc7f1b..3ca65ee4356 100644 --- a/modules/vfs/ios/HippyFileHandler.h +++ b/modules/vfs/ios/HippyFileHandler.h @@ -43,8 +43,8 @@ class HippyFileHandler : public VFSUriHandler { /// Convert relative addresses(such as hpfile://) to absolute paths /// - Parameters: /// - hippyFileUrl: file url - /// - hippySandboxDirectory: sandbox directory of hippy app - static NSURL *AbsoluteURLFromHippyFileURL(NSURL *hippyFileUrl, NSURL *hippySandboxDirectory); + /// - bridge: HippyBridge, use to get sandbox url + static NSURL *AbsoluteURLFromHippyFileURL(NSURL *hippyFileUrl, HippyBridge *bridge); virtual void RequestUntrustedContent(NSURLRequest *request, NSDictionary *extraInfo, diff --git a/modules/vfs/ios/HippyFileHandler.mm b/modules/vfs/ios/HippyFileHandler.mm index f74be7b4218..cd308b70c49 100644 --- a/modules/vfs/ios/HippyFileHandler.mm +++ b/modules/vfs/ios/HippyFileHandler.mm @@ -41,7 +41,7 @@ FOOTSTONE_UNIMPLEMENTED(); } -NSURL *HippyFileHandler::AbsoluteURLFromHippyFileURL(NSURL *fileUrl, NSURL *hippySandboxDirectory) { +NSURL *HippyFileHandler::AbsoluteURLFromHippyFileURL(NSURL *fileUrl, HippyBridge *bridge) { static NSString *defaultHippyLocalFileURLPrefix = @"hpfile://"; static NSString *hippyLocalRelativeFilePathPrefix = @"./"; static NSString *hippyLocalAppBundleFilePathPrefix = @"appbundle/"; @@ -55,6 +55,7 @@ if ([path hasPrefix:hippyLocalRelativeFilePathPrefix]) { // Hippy Sandbox Relative Path NSString *relativePath = [path substringFromIndex:hippyLocalRelativeFilePathPrefix.length]; + NSURL *hippySandboxDirectory = [NSURL URLWithString:bridge.sandboxDirectory]; absoluteURL = [NSURL fileURLWithPath:relativePath relativeToURL:hippySandboxDirectory]; } else if ([path hasPrefix:hippyLocalAppBundleFilePathPrefix]) { // App Bundle Path @@ -90,7 +91,7 @@ return; } - NSURL *absoluteURL = AbsoluteURLFromHippyFileURL(url, [NSURL URLWithString:bridge.sandboxDirectory]); + NSURL *absoluteURL = AbsoluteURLFromHippyFileURL(url, bridge); if ([absoluteURL isFileURL] || [absoluteURL isFileReferenceURL]) { void (^opBlock)() = ^{ NSError *error;