aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Library/PathExtensions.cs
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2021-05-05 16:43:20 +0200
committerBond_009 <bond.009@outlook.com>2021-05-05 16:45:04 +0200
commit47e7c1356c1364e5e834ce37cd4a9ace5e2d838e (patch)
tree5db7e1730c8de0a9e901023141106c718dd7a3fb /Emby.Server.Implementations/Library/PathExtensions.cs
parentb6df85136347df691ebc774b9d48dc622cb63a04 (diff)
PathExtensions: Fix index out of bounds in TryReplaceSubPath
Fixes #5977
Diffstat (limited to 'Emby.Server.Implementations/Library/PathExtensions.cs')
-rw-r--r--Emby.Server.Implementations/Library/PathExtensions.cs10
1 files changed, 8 insertions, 2 deletions
diff --git a/Emby.Server.Implementations/Library/PathExtensions.cs b/Emby.Server.Implementations/Library/PathExtensions.cs
index 770cf6bb0..0de4edb7e 100644
--- a/Emby.Server.Implementations/Library/PathExtensions.cs
+++ b/Emby.Server.Implementations/Library/PathExtensions.cs
@@ -96,8 +96,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;
}