Skip to content

Commit

Permalink
fix(ios): potential thread race in vfs file module
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Oct 30, 2024
1 parent 84a02fa commit 0fcfdc7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion framework/ios/base/bridge/HippyBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ HIPPY_EXTERN NSString *HippyBridgeModuleNameForClass(Class bridgeModuleClass);
@property (nonatomic, copy, readonly) NSArray<NSURL *> *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.
Expand Down
4 changes: 2 additions & 2 deletions modules/vfs/ios/HippyFileHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions modules/vfs/ios/HippyFileHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0fcfdc7

Please sign in to comment.