From e4bc5853add9ece195faaf9b217ebf565df27670 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sun, 16 Oct 2022 14:59:19 -0700 Subject: [PATCH] Fix a crash with embedded cue sheet handling Tag reading can read cue sheets as either a single NSString, or an NSArray of NSStrings, so handle either case. Signed-off-by: Christopher Snowhill --- Plugins/CueSheet/CueSheetContainer.m | 31 ++++++++++++++++++++--- Plugins/CueSheet/CueSheetDecoder.m | 31 ++++++++++++++++++++--- Plugins/CueSheet/CueSheetMetadataReader.m | 31 ++++++++++++++++++++--- 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/Plugins/CueSheet/CueSheetContainer.m b/Plugins/CueSheet/CueSheetContainer.m index 234383576..87a80712d 100644 --- a/Plugins/CueSheet/CueSheetContainer.m +++ b/Plugins/CueSheet/CueSheetContainer.m @@ -50,11 +50,34 @@ NSDictionary *alsoMetadata = [NSClassFromString(@"AudioPropertiesReader") propertiesForURL:url skipCue:YES]; - NSString *sheet = [fileMetadata objectForKey:@"cuesheet"]; - if(!sheet || ![sheet length]) sheet = [alsoMetadata objectForKey:@"cuesheet"]; + id sheet = [fileMetadata objectForKey:@"cuesheet"]; + NSString *sheetString = nil; + if(sheet) { + if([sheet isKindOfClass:[NSArray class]]) { + NSArray *sheetContainer = sheet; + if([sheetContainer count]) { + sheetString = sheetContainer[0]; + } + } else if([sheet isKindOfClass:[NSString class]]) { + sheetString = sheet; + } + } + if(!sheetString || ![sheetString length]) { + sheet = [alsoMetadata objectForKey:@"cuesheet"]; + if(sheet) { + if([sheet isKindOfClass:[NSArray class]]) { + NSArray *sheetContainer = sheet; + if([sheetContainer count]) { + sheetString = sheetContainer[0]; + } + } else if([sheet isKindOfClass:[NSString class]]) { + sheetString = sheet; + } + } + } - if([sheet length]) { - cuesheet = [CueSheet cueSheetWithString:sheet withFilename:[url path]]; + if(sheetString && [sheetString length]) { + cuesheet = [CueSheet cueSheetWithString:sheetString withFilename:[url path]]; } embedded = YES; } else diff --git a/Plugins/CueSheet/CueSheetDecoder.m b/Plugins/CueSheet/CueSheetDecoder.m index c32fdba41..6aab78079 100644 --- a/Plugins/CueSheet/CueSheetDecoder.m +++ b/Plugins/CueSheet/CueSheetDecoder.m @@ -92,11 +92,34 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext; NSDictionary *alsoMetadata = [decoder metadata]; - NSString *sheet = [fileMetadata objectForKey:@"cuesheet"]; - if(!sheet || ![sheet length]) sheet = [alsoMetadata objectForKey:@"cuesheet"]; + id sheet = [fileMetadata objectForKey:@"cuesheet"]; + NSString *sheetString = nil; + if(sheet) { + if([sheet isKindOfClass:[NSArray class]]) { + NSArray *sheetContainer = sheet; + if([sheetContainer count]) { + sheetString = sheetContainer[0]; + } + } else if([sheet isKindOfClass:[NSString class]]) { + sheetString = sheet; + } + } + if(!sheetString || ![sheetString length]) { + sheet = [alsoMetadata objectForKey:@"cuesheet"]; + if(sheet) { + if([sheet isKindOfClass:[NSArray class]]) { + NSArray *sheetContainer = sheet; + if([sheetContainer count]) { + sheetString = sheetContainer[0]; + } + } else if([sheet isKindOfClass:[NSString class]]) { + sheetString = sheet; + } + } + } - if([sheet length]) { - cuesheet = [CueSheet cueSheetWithString:sheet withFilename:[url path]]; + if(sheetString && [sheetString length]) { + cuesheet = [CueSheet cueSheetWithString:sheetString withFilename:[url path]]; embedded = YES; } diff --git a/Plugins/CueSheet/CueSheetMetadataReader.m b/Plugins/CueSheet/CueSheetMetadataReader.m index 3f7f0bde6..c42fae680 100644 --- a/Plugins/CueSheet/CueSheetMetadataReader.m +++ b/Plugins/CueSheet/CueSheetMetadataReader.m @@ -46,11 +46,34 @@ NSDictionary *alsoMetadata = [NSClassFromString(@"AudioPropertiesReader") propertiesForURL:url skipCue:YES]; - NSString *sheet = [fileMetadata objectForKey:@"cuesheet"]; - if(!sheet || ![sheet length]) sheet = [alsoMetadata objectForKey:@"cuesheet"]; + id sheet = [fileMetadata objectForKey:@"cuesheet"]; + NSString *sheetString = nil; + if(sheet) { + if([sheet isKindOfClass:[NSArray class]]) { + NSArray *sheetContainer = sheet; + if([sheetContainer count]) { + sheetString = sheetContainer[0]; + } + } else if([sheet isKindOfClass:[NSString class]]) { + sheetString = sheet; + } + } + if(!sheetString || ![sheetString length]) { + sheet = [alsoMetadata objectForKey:@"cuesheet"]; + if(sheet) { + if([sheet isKindOfClass:[NSArray class]]) { + NSArray *sheetContainer = sheet; + if([sheetContainer count]) { + sheetString = sheetContainer[0]; + } + } else if([sheet isKindOfClass:[NSString class]]) { + sheetString = sheet; + } + } + } - if([sheet length]) { - cuesheet = [CueSheet cueSheetWithString:sheet withFilename:[url path]]; + if(sheetString && [sheetString length]) { + cuesheet = [CueSheet cueSheetWithString:sheetString withFilename:[url path]]; embedded = YES; } } else