peass-ng/PEASS-ng · error · ArgumentOutOfRangeException
Specified argument was out of the range of valid values. (Pa
Error message
Specified argument was out of the range of valid values. (Parameter 'arrayIndex')
What it means
TaskFolderCollection.CopyTo validates the destination index first and throws ArgumentOutOfRangeException when arrayIndex is negative. It is a standard ICollection.CopyTo guard ensuring the copy starts at a valid position.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs:116
{
for (var i = v2FolderList.Count; i > 0; i--)
if (string.Equals(item.Path, v2FolderList[i].Path, StringComparison.CurrentCultureIgnoreCase))
return true;
}
else
return item.Path == "\\";
return false;
}
/// <summary>Copies the elements of the ICollection to an Array, starting at a particular Array index.</summary>
/// <param name="array">
/// The one-dimensional Array that is the destination of the elements copied from <see cref="ICollection{T}"/>. The Array must have
/// zero-based indexing.
/// </param>
/// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
public void CopyTo(TaskFolder[] array, int arrayIndex)
{
if (arrayIndex < 0) throw new ArgumentOutOfRangeException(nameof(arrayIndex));
if (array == null) throw new ArgumentNullException(nameof(array));
if (v2FolderList != null)
{
if (arrayIndex + Count > array.Length)
throw new ArgumentException();
foreach (var f in this)
array[arrayIndex++] = f;
}
else
{
if (arrayIndex + v1FolderList.Length > array.Length)
throw new ArgumentException();
v1FolderList.CopyTo(array, arrayIndex);
}
}
/// <summary>Releases all resources used by this class.</summary>
public void Dispose()View on GitHub (pinned to 53fb989abc)
Solutions
- Ensure arrayIndex >= 0 before calling CopyTo
- Prefer enumerating the collection with foreach instead of CopyTo
- Use ToArray()/ToList() style copying via LINQ
Example fix
// before
int idx = folders.Select(f => f.Name).ToList().IndexOf("x") - 1;
subFolders.CopyTo(arr, idx);
// after
if (idx >= 0 && idx < arr.Length) subFolders.CopyTo(arr, idx); Defensive patterns
Strategy: validation
Validate before calling
if (array == null || arrayIndex < 0 || array.Length - arrayIndex < subFolders.Count)
throw new ArgumentException("Destination array too small or invalid index."); Prevention
- Assert arrayIndex >= 0 before CopyTo
- Prefer foreach or ToArray() over manual CopyTo
- Keep index arithmetic (offsets) in one validated helper
When it happens
Trigger: Calling CopyTo(array, -1) or passing an index computed from a failed search/offset that ended up negative.
Common situations: Copying SubFolders into a preallocated array with an off-by-one or uninitialized index variable.
Related errors
- Specified argument was out of the range of valid values. (Pa
- Value cannot be null. (Parameter 'array')
- Exception of type 'System.ArgumentException' was thrown.
- On systems prior to Windows 10, all individual parameters mu
- A maximum of 32 parameters can be supplied to RunEx.
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/948c301b566d6a8a.
Report an issue: GitHub.