Bug Description
In GetProcessesUsingFile(), int.Parse() is used to convert the PID from the regex match. Although the regex captures \d+, a match with an extremely large number could cause an OverflowException, and any future regex change could introduce FormatException. Using int.TryParse() would make this robust without relying on the regex pattern as the sole safety net.
Actual Behavior
// HandleHelper.cs lines 73-77
processes.Add(new ProcessHandleInfo
{
ProcessName = match.Groups["name"].Value.Trim(),
ProcessId = int.Parse(match.Groups["pid"].Value)
});
If handle.exe outputs a PID exceeding int.MaxValue (2,147,483,647), this throws an unhandled OverflowException and aborts the entire enumeration.
Suggested Fix
Use int.TryParse() and skip invalid entries instead of crashing:
foreach (Match match in regex.Matches(output))
{
if (match.Success && int.TryParse(match.Groups["pid"].Value, out int pid))
{
processes.Add(new ProcessHandleInfo
{
ProcessName = match.Groups["name"].Value.Trim(),
ProcessId = pid
});
}
}
Environment
- File:
src/Servy.Core/Helpers/HandleHelper.cs
- Line: 76
Bug Description
In
GetProcessesUsingFile(),int.Parse()is used to convert the PID from the regex match. Although the regex captures\d+, a match with an extremely large number could cause anOverflowException, and any future regex change could introduceFormatException. Usingint.TryParse()would make this robust without relying on the regex pattern as the sole safety net.Actual Behavior
If
handle.exeoutputs a PID exceedingint.MaxValue(2,147,483,647), this throws an unhandledOverflowExceptionand aborts the entire enumeration.Suggested Fix
Use
int.TryParse()and skip invalid entries instead of crashing:Environment
src/Servy.Core/Helpers/HandleHelper.cs