From 34f3ed0a4d8d233cd4415e65f81c97f9d2e4d104 Mon Sep 17 00:00:00 2001 From: JPVenson Date: Tue, 29 Oct 2024 14:10:58 +0000 Subject: [PATCH 1/2] Fixed Stackoverflow on MediaSourceCount --- MediaBrowser.Controller/Entities/Video.cs | 31 +++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 04f47b729d..3a86ac24aa 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -152,16 +152,7 @@ namespace MediaBrowser.Controller.Entities { get { - if (!string.IsNullOrEmpty(PrimaryVersionId)) - { - var item = LibraryManager.GetItemById(PrimaryVersionId); - if (item is Video video) - { - return video.MediaSourceCount; - } - } - - return LinkedAlternateVersions.Length + LocalAlternateVersions.Length + 1; + return GetMediaSourceCount(new Stack()); } } @@ -550,5 +541,25 @@ namespace MediaBrowser.Controller.Entities return list; } + + private int GetMediaSourceCount(Stack callstack) + { + if (!string.IsNullOrEmpty(PrimaryVersionId)) + { + var item = LibraryManager.GetItemById(PrimaryVersionId); + if (item is Video video) + { + if (callstack.Contains(video.Id)) + { + return video.LinkedAlternateVersions.Length + video.LocalAlternateVersions.Length + 1; + } + + callstack.Push(video.Id); + return video.GetMediaSourceCount(callstack); + } + } + + return LinkedAlternateVersions.Length + LocalAlternateVersions.Length + 1; + } } } From ba28e3041d73819b1d4f70d127ec7ae97ec42139 Mon Sep 17 00:00:00 2001 From: JPVenson Date: Tue, 29 Oct 2024 14:28:02 +0000 Subject: [PATCH 2/2] Changed stack type --- MediaBrowser.Controller/Entities/Video.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 3a86ac24aa..03d62b1b08 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -152,7 +152,7 @@ namespace MediaBrowser.Controller.Entities { get { - return GetMediaSourceCount(new Stack()); + return GetMediaSourceCount(new HashSet()); } } @@ -542,7 +542,7 @@ namespace MediaBrowser.Controller.Entities return list; } - private int GetMediaSourceCount(Stack callstack) + private int GetMediaSourceCount(HashSet callstack) { if (!string.IsNullOrEmpty(PrimaryVersionId)) { @@ -554,7 +554,7 @@ namespace MediaBrowser.Controller.Entities return video.LinkedAlternateVersions.Length + video.LocalAlternateVersions.Length + 1; } - callstack.Push(video.Id); + callstack.Add(video.Id); return video.GetMediaSourceCount(callstack); } }