Procházet zdrojové kódy

Make a precheck if we're trying to download a file within our directory. If not simply return nil which is handled as resource not found

Carola Nitz před 7 roky
rodič
revize
984bea7f56
1 změnil soubory, kde provedl 16 přidání a 0 odebrání
  1. 16 0
      Sources/VLCHTTPConnection.m

+ 16 - 0
Sources/VLCHTTPConnection.m

@@ -106,10 +106,26 @@
     return [[HTTPDataResponse alloc] initWithData:[@"\"OK\"" dataUsingEncoding:NSUTF8StringEncoding]];
 }
 
+- (BOOL)fileIsInDocumentFolder:(NSString*)filepath
+{
+    NSError *error;
+    NSURLRelationship relationship;
+
+    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    NSString *directoryPath = [searchPaths firstObject];
+
+    [[NSFileManager defaultManager] getRelationship:&relationship ofDirectoryAtURL:[NSURL fileURLWithPath:directoryPath] toItemAtURL:[NSURL fileURLWithPath:filepath] error:&error];
+    return relationship == NSURLRelationshipContains;
+}
+
 #if TARGET_OS_IOS
 - (NSObject<HTTPResponse> *)_httpGETDownloadForPath:(NSString *)path
 {
     NSString *filePath = [[path stringByReplacingOccurrencesOfString:@"/download/" withString:@""]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+    if (![self fileIsInDocumentFolder:filePath]) {
+       //return nil which gets handled as resource not found
+        return nil;
+    }
     HTTPFileResponse *fileResponse = [[HTTPFileResponse alloc] initWithFilePath:filePath forConnection:self];
     fileResponse.contentType = @"application/octet-stream";
     return fileResponse;