From b8d6ab5c8cfa4c8637e4bf2e7602d20218276202 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 9 Jun 2025 23:54:42 -0700 Subject: [PATCH] Bug Fixes: Some more generic NULL URL checks Also catch some invalid URLs in the database. Signed-off-by: Christopher Snowhill --- Playlist/PlaylistLoader.m | 7 +++++-- Plugins/FileSource/FileSource.m | 6 ++++++ Plugins/FileSource/FileSource.xcodeproj/project.pbxproj | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index f2054135b..d8ab1eefd 100644 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -392,7 +392,9 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc for(url in urls) { id pathTask = [sandboxTask startChildWithOperation:@"Process one folder" description:[NSString stringWithFormat:@"Processing file or folder: %@", url]]; @try { + if(!url) continue; if([url isFileURL]) { + if(![url path]) continue; BOOL isDir; if([[NSFileManager defaultManager] fileExistsAtPath:[url path] isDirectory:&isDir]) { if(isDir == YES) { @@ -419,6 +421,7 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc } } else { // Non-file URL.. + if(![url absoluteString]) continue; [expandedURLs setValue:url forKey:[PlaylistLoader keyForPath:[url absoluteString]]]; } @@ -810,7 +813,7 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path); - (void)loadInfoForEntries:(NSArray *)entries { NSMutableDictionary *queueThisJob = [[NSMutableDictionary alloc] init]; for(PlaylistEntry *pe in entries) { - if(!pe || !pe.urlString || pe.deLeted || pe.metadataLoaded) continue; + if(!pe || !pe.urlString || ![pe.urlString length] || pe.deLeted || pe.metadataLoaded) continue; NSString *path = pe.urlString; NSMutableArray *entrySet = [queueThisJob objectForKey:path]; @@ -1160,7 +1163,7 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path); NSMutableIndexSet *pruneSet = [[NSMutableIndexSet alloc] init]; NSUInteger index = 0; for(PlaylistEntry *pe in resultsCopy) { - if(pe.deLeted || !pe.urlString || [pe.urlString length] < 1) { + if(pe.deLeted || !pe.urlString || ![pe.urlString length]) { [pruneSet addIndex:index]; [moc deleteObject:pe]; } diff --git a/Plugins/FileSource/FileSource.m b/Plugins/FileSource/FileSource.m index 70d975fa6..832de277b 100644 --- a/Plugins/FileSource/FileSource.m +++ b/Plugins/FileSource/FileSource.m @@ -10,6 +10,8 @@ #import "SandboxBroker.h" +#import "Logging.h" + @implementation FileSource + (void)initialize { @@ -34,6 +36,10 @@ sbHandle = [sandboxBroker beginFolderAccess:url]; NSString *path = [url path]; + if(!path) { + ALog(@"Invalid URL: %@", url); + return NO; + } fex_type_t type; fex_err_t error = fex_identify_file(&type, [path UTF8String]); diff --git a/Plugins/FileSource/FileSource.xcodeproj/project.pbxproj b/Plugins/FileSource/FileSource.xcodeproj/project.pbxproj index 8ba3bb9e8..526c310a4 100644 --- a/Plugins/FileSource/FileSource.xcodeproj/project.pbxproj +++ b/Plugins/FileSource/FileSource.xcodeproj/project.pbxproj @@ -40,6 +40,7 @@ 8307D31B2860722C000FF8EB /* SandboxBroker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SandboxBroker.h; path = ../../Utils/SandboxBroker.h; sourceTree = ""; }; 8335FF6817FF765A002D8DD2 /* File_Extractor.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = File_Extractor.xcodeproj; path = ../../Frameworks/File_Extractor/File_Extractor.xcodeproj; sourceTree = ""; }; 834A42AD287AF25600EB9D9B /* AudioChunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioChunk.h; path = ../../Audio/Chain/AudioChunk.h; sourceTree = ""; }; + 835F15B82DF80DE1008C7054 /* Logging.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Logging.h; path = /Users/chris/Source/Repos/cog/Utils/Logging.h; sourceTree = ""; }; 83747C4F2862DD2F0021245F /* Shared.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Shared.xcconfig; sourceTree = ""; }; 8D5B49B6048680CD000E48DA /* FileSource.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FileSource.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -93,6 +94,7 @@ isa = PBXGroup; children = ( 834A42AD287AF25600EB9D9B /* AudioChunk.h */, + 835F15B82DF80DE1008C7054 /* Logging.h */, 8307D31B2860722C000FF8EB /* SandboxBroker.h */, 17ADB4080B979A8A00257CA2 /* Plugin.h */, 17ADB4180B979AEB00257CA2 /* FileSource.h */,