Skip to content

Commit

Permalink
fix(storage): bug when getting the root ref of a bucket (#3455)
Browse files Browse the repository at this point in the history
A bug crashes the app when trying to list objects, root urls don't have a "/" so rangeOfString gives location == NSNotFound, if it goes unchecked rangeOfSlash.location + 5 creates range outside the bounds

Co-authored-by: Mike Hardy <github@mikehardy.net>
  • Loading branch information
Adrxx and mikehardy authored Oct 6, 2020
1 parent 743edf8 commit 02132ce
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/storage/ios/RNFBStorage/RNFBStorageModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,11 @@ - (void)addUploadTaskObservers:(FIRStorageUploadTask *)uploadTask appDisplayName

- (FIRStorageReference *)getReferenceFromUrl:(NSString *)url app:(FIRApp *)firebaseApp {
NSString *pathWithBucketName = [url substringWithRange:NSMakeRange(5, [url length] - 5)];
NSString *bucket = [url substringWithRange:NSMakeRange(0, [pathWithBucketName rangeOfString:@"/"].location + 5)];
NSString *bucket = url;
NSRange rangeOfSlash = [pathWithBucketName rangeOfString:@"/"];
if (rangeOfSlash.location != NSNotFound) {
bucket = [url substringWithRange:NSMakeRange(0, rangeOfSlash.location + 5)];
}
return [[FIRStorage storageForApp:firebaseApp URL:bucket] referenceForURL:url];
}

Expand Down

1 comment on commit 02132ce

@vercel
Copy link

@vercel vercel bot commented on 02132ce Oct 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.