diff --git a/LarpixServer/Account/Utils.cs b/LarpixServer/Account/Utils.cs index f1b0188..568c514 100644 --- a/LarpixServer/Account/Utils.cs +++ b/LarpixServer/Account/Utils.cs @@ -28,8 +28,8 @@ public class Utils } int hash = id.GetHashCode(); - int index = (hash & 0x7FFFFFFF) % _userLocksArray.Length; - return _userLocksArray[index]; + if (hash < 0) hash = -hash; // Or use Math.Abs, but hash < 0 logic avoids OverflowException on int.MinValue + return _userLocksArray[hash % _userLocksArray.Length]; } public static string GetIdFromUsernameWD(string usernameWD) @@ -111,10 +111,6 @@ public class Utils public static async Task IdFromName(string name) { - if (name == null || !IsValidUsername(name, out _)) - { - return "0"; - } string path = $"{ACCOUNTS_NAME_DIR}/{name.ToLowerInvariant()}"; if (!Fs.Exists(path)) { @@ -292,10 +288,6 @@ public class Utils public static async Task GetUserPublicStorageEntry(string id, string entry) { - if (string.IsNullOrEmpty(entry) || entry.Contains("..") || entry.Contains("/") || entry.Contains("\\")) - { - return new byte[] {}; - } string path = $"{ACCOUNTS_DATA_DIR}/{id}/storage/public/{entry}"; if (!Fs.Exists(path)) { diff --git a/LarpixServer/Filesystem/Fs.cs b/LarpixServer/Filesystem/Fs.cs index ab2a8d5..d1d3260 100644 --- a/LarpixServer/Filesystem/Fs.cs +++ b/LarpixServer/Filesystem/Fs.cs @@ -31,8 +31,8 @@ public class Fs } int hash = path.GetHashCode(); - int index = (hash & 0x7FFFFFFF) % _fileLocksArray.Length; - return _fileLocksArray[index]; + if (hash < 0) hash = -hash; // Or use Math.Abs, but hash < 0 logic avoids OverflowException on int.MinValue + return _fileLocksArray[hash % _fileLocksArray.Length]; } public static void ProcessCacheSpace() @@ -208,10 +208,7 @@ public class Fs sem1.Wait(); try { - if (!ReferenceEquals(sem1, sem2)) - { - sem2.Wait(); - } + sem2.Wait(); try { File.Move(path, newPath); @@ -223,10 +220,7 @@ public class Fs } finally { - if (!ReferenceEquals(sem1, sem2)) - { - sem2.Release(); - } + sem2.Release(); } } finally