From 554d1b2ca8868e7aeb1fa9acac75cb8ce423796a Mon Sep 17 00:00:00 2001 From: Stanislav Ionascu Date: Tue, 4 Jan 2022 21:52:52 +0000 Subject: [PATCH] Fix #7100 by catching the exception on opening invalid UDF images When an invalid UDF image is opened by the UdfReader, it may throw and exception. This change is to catch and log the exception. --- .../Library/LibraryManager.cs | 9 +++--- .../Library/Resolvers/BaseVideoResolver.cs | 31 +++++++++++++------ .../Library/Resolvers/ExtraResolver.cs | 8 +++-- .../Library/Resolvers/GenericVideoResolver.cs | 8 +++-- .../Library/Resolvers/Movies/MovieResolver.cs | 6 ++-- .../Library/Resolvers/TV/EpisodeResolver.cs | 6 ++-- .../Library/EpisodeResolverTest.cs | 9 +++--- .../Library/LibraryManager/FindExtrasTests.cs | 2 +- .../Library/MovieResolverTests.cs | 3 +- 9 files changed, 52 insertions(+), 30 deletions(-) diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index e3be5627fb..0770bdbc3d 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -46,6 +46,7 @@ using MediaBrowser.Model.Library; using MediaBrowser.Model.Querying; using MediaBrowser.Model.Tasks; using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Episode = MediaBrowser.Controller.Entities.TV.Episode; using EpisodeInfo = Emby.Naming.TV.EpisodeInfo; @@ -99,7 +100,7 @@ namespace Emby.Server.Implementations.Library /// Initializes a new instance of the class. /// /// The application host. - /// The logger. + /// The logger factory. /// The task manager. /// The user manager. /// The configuration manager. @@ -115,7 +116,7 @@ namespace Emby.Server.Implementations.Library /// The naming options. public LibraryManager( IServerApplicationHost appHost, - ILogger logger, + ILoggerFactory loggerFactory, ITaskManager taskManager, IUserManager userManager, IServerConfigurationManager configurationManager, @@ -131,7 +132,7 @@ namespace Emby.Server.Implementations.Library NamingOptions namingOptions) { _appHost = appHost; - _logger = logger; + _logger = loggerFactory.CreateLogger(); _taskManager = taskManager; _userManager = userManager; _configurationManager = configurationManager; @@ -146,7 +147,7 @@ namespace Emby.Server.Implementations.Library _memoryCache = memoryCache; _namingOptions = namingOptions; - _extraResolver = new ExtraResolver(namingOptions); + _extraResolver = new ExtraResolver(loggerFactory.CreateLogger(), namingOptions); _configurationManager.ConfigurationUpdated += ConfigurationUpdated; diff --git a/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs b/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs index 9222a94797..3d6b9f3b62 100644 --- a/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/BaseVideoResolver.cs @@ -12,6 +12,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; +using Microsoft.Extensions.Logging; namespace Emby.Server.Implementations.Library.Resolvers { @@ -22,8 +23,11 @@ namespace Emby.Server.Implementations.Library.Resolvers public abstract class BaseVideoResolver : MediaBrowser.Controller.Resolvers.ItemResolver where T : Video, new() { - protected BaseVideoResolver(NamingOptions namingOptions) + private readonly ILogger _logger; + + protected BaseVideoResolver(ILogger logger, NamingOptions namingOptions) { + _logger = logger; NamingOptions = namingOptions; } @@ -156,19 +160,26 @@ namespace Emby.Server.Implementations.Library.Resolvers } else { - // use disc-utils, both DVDs and BDs use UDF filesystem - using (var videoFileStream = File.Open(video.Path, FileMode.Open, FileAccess.Read)) - using (UdfReader udfReader = new UdfReader(videoFileStream)) + try { - if (udfReader.DirectoryExists("VIDEO_TS")) - { - video.IsoType = IsoType.Dvd; - } - else if (udfReader.DirectoryExists("BDMV")) + // use disc-utils, both DVDs and BDs use UDF filesystem + using (var videoFileStream = File.Open(video.Path, FileMode.Open, FileAccess.Read)) + using (UdfReader udfReader = new UdfReader(videoFileStream)) { - video.IsoType = IsoType.BluRay; + if (udfReader.DirectoryExists("VIDEO_TS")) + { + video.IsoType = IsoType.Dvd; + } + else if (udfReader.DirectoryExists("BDMV")) + { + video.IsoType = IsoType.BluRay; + } } } + catch (Exception ex) + { + _logger.LogError(ex, "Error opening UDF/ISO image: {Value}", video.Path ?? video.Name); + } } } } diff --git a/Emby.Server.Implementations/Library/Resolvers/ExtraResolver.cs b/Emby.Server.Implementations/Library/Resolvers/ExtraResolver.cs index 807913b5d6..408e640f9d 100644 --- a/Emby.Server.Implementations/Library/Resolvers/ExtraResolver.cs +++ b/Emby.Server.Implementations/Library/Resolvers/ExtraResolver.cs @@ -6,6 +6,7 @@ using Emby.Naming.Video; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Model.Entities; +using Microsoft.Extensions.Logging; using static Emby.Naming.Video.ExtraRuleResolver; namespace Emby.Server.Implementations.Library.Resolvers @@ -22,12 +23,13 @@ namespace Emby.Server.Implementations.Library.Resolvers /// /// Initializes a new instance of the class. /// + /// The logger. /// An instance of . - public ExtraResolver(NamingOptions namingOptions) + public ExtraResolver(ILogger logger, NamingOptions namingOptions) { _namingOptions = namingOptions; - _trailerResolvers = new IItemResolver[] { new GenericVideoResolver(namingOptions) }; - _videoResolvers = new IItemResolver[] { new GenericVideoResolver