Merge pull request #5987 from Bond-009/ioob
PathExtensions: Fix index out of bounds in TryReplaceSubPath
This commit is contained in:
commit
a6ee4632ce
|
@ -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
|
// 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
|
// when the sub path matches a similar but in-complete subpath
|
||||||
var oldSubPathEndsWithSeparator = subPath[^1] == newDirectorySeparatorChar;
|
var oldSubPathEndsWithSeparator = subPath[^1] == newDirectorySeparatorChar;
|
||||||
if (!path.StartsWith(subPath, StringComparison.OrdinalIgnoreCase)
|
if (!path.StartsWith(subPath, StringComparison.OrdinalIgnoreCase))
|
||||||
|| (!oldSubPathEndsWithSeparator && path[subPath.Length] != newDirectorySeparatorChar))
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.Length > subPath.Length
|
||||||
|
&& !oldSubPathEndsWithSeparator
|
||||||
|
&& path[subPath.Length] != newDirectorySeparatorChar)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace Jellyfin.Server.Implementations.Tests.Library
|
||||||
[InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff", "/home/jeff/", "/home/jeff/myfile.mkv")]
|
[InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff", "/home/jeff/", "/home/jeff/myfile.mkv")]
|
||||||
[InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff/", "/home/jeff/", "/home/jeff/myfile.mkv")]
|
[InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff/", "/home/jeff/", "/home/jeff/myfile.mkv")]
|
||||||
[InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff/", "/", "/myfile.mkv")]
|
[InlineData("C:\\Users\\jeff\\myfile.mkv", "C:\\Users/jeff/", "/", "/myfile.mkv")]
|
||||||
|
[InlineData("/o", "/o", "/s", "/s")] // regression test for #5977
|
||||||
public void TryReplaceSubPath_ValidArgs_Correct(string path, string subPath, string newSubPath, string? expectedResult)
|
public void TryReplaceSubPath_ValidArgs_Correct(string path, string subPath, string newSubPath, string? expectedResult)
|
||||||
{
|
{
|
||||||
Assert.True(PathExtensions.TryReplaceSubPath(path, subPath, newSubPath, out var result));
|
Assert.True(PathExtensions.TryReplaceSubPath(path, subPath, newSubPath, out var result));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user