From 6386606a5338bc1337dfcfb5ff71267bec6c3e60 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Wed, 5 May 2021 17:20:14 +0200 Subject: Merge pull request #5987 from Bond-009/ioob PathExtensions: Fix index out of bounds in TryReplaceSubPath (cherry picked from commit a6ee4632ce618e60909aa4310e33d60dcdfc1aec) Signed-off-by: Joshua M. Boniface --- Emby.Server.Implementations/Library/PathExtensions.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Emby.Server.Implementations/Library/PathExtensions.cs') diff --git a/Emby.Server.Implementations/Library/PathExtensions.cs b/Emby.Server.Implementations/Library/PathExtensions.cs index 7dcc925c2..539adae21 100644 --- a/Emby.Server.Implementations/Library/PathExtensions.cs +++ b/Emby.Server.Implementations/Library/PathExtensions.cs @@ -90,8 +90,14 @@ namespace Emby.Server.Implementations.Library // We have to ensure that the sub path ends with a directory separator otherwise we'll get weird results // when the sub path matches a similar but in-complete subpath var oldSubPathEndsWithSeparator = subPath[^1] == newDirectorySeparatorChar; - if (!path.StartsWith(subPath, StringComparison.OrdinalIgnoreCase) - || (!oldSubPathEndsWithSeparator && path[subPath.Length] != newDirectorySeparatorChar)) + if (!path.StartsWith(subPath, StringComparison.OrdinalIgnoreCase)) + { + return false; + } + + if (path.Length > subPath.Length + && !oldSubPathEndsWithSeparator + && path[subPath.Length] != newDirectorySeparatorChar) { return false; } -- cgit v1.2.3