From e96a4efa68a79d8b0380e3e8d59b6c23ebaab294 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 9 Jun 2022 23:18:51 -0700 Subject: [PATCH] [Metadata Loading] Added null pointer guards This prevents crashes where inputs were not returning either properties or metadata blocks and the file open cache was attempting to cache the resulting nil pointer as if it were valid. Also prevent the metadata redundant string coalescing from processing nil objects as well, in case it's used that way somewhere else. Signed-off-by: Christopher Snowhill --- Audio/PluginController.mm | 4 ++++ Utils/RedundantPlaylistDataStore.m | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Audio/PluginController.mm b/Audio/PluginController.mm index 71a5b4e7e..7d35c5ecc 100644 --- a/Audio/PluginController.mm +++ b/Audio/PluginController.mm @@ -49,6 +49,8 @@ static void cache_deinit() { } static void cache_insert_properties(NSURL *url, NSDictionary *properties) { + if(properties == nil) return; + std::lock_guard lock(Cache_Lock); std::string path = [[url absoluteString] UTF8String]; @@ -61,6 +63,8 @@ static void cache_insert_properties(NSURL *url, NSDictionary *properties) { } static void cache_insert_metadata(NSURL *url, NSDictionary *metadata) { + if(metadata == nil) return; + std::lock_guard lock(Cache_Lock); std::string path = [[url absoluteString] UTF8String]; diff --git a/Utils/RedundantPlaylistDataStore.m b/Utils/RedundantPlaylistDataStore.m index 19c00d82e..904ba6264 100644 --- a/Utils/RedundantPlaylistDataStore.m +++ b/Utils/RedundantPlaylistDataStore.m @@ -52,6 +52,8 @@ } - (NSDictionary *)coalesceEntryInfo:(NSDictionary *)entryInfo { + if(entryInfo == nil) return entryInfo; + __block NSMutableDictionary *ret = [[NSMutableDictionary alloc] initWithCapacity:[entryInfo count]]; [entryInfo enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL *_Nonnull stop) {