peass-ng/PEASS-ng · error · ArgumentException

Exception of type 'System.ArgumentException' was thrown.

Error message

Exception of type 'System.ArgumentException' was thrown.

What it means

CopyTo throws a plain ArgumentException when the destination array is too small: for v2 folders, arrayIndex + Count exceeds array.Length (and similarly for the v1 list). There is not enough room from arrayIndex to fit all folders.

Source

Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs:121

            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()
        {
            if (v1FolderList != null && v1FolderList.Length > 0)
            {
                v1FolderList[0].Dispose();
                v1FolderList[0] = null;

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Size the array as collection.Count + arrayIndex
  2. Re-read Count immediately before CopyTo
  3. Use ToArray()/foreach enumeration instead

Example fix

// before
var arr = new TaskFolder[10];
subFolders.CopyTo(arr, 5);
// after
var arr = new TaskFolder[subFolders.Count + 5];
subFolders.CopyTo(arr, 5);
Defensive patterns

Strategy: validation

Validate before calling

if (array == null || arrayIndex < 0 || arrayIndex + subFolders.Count > array.Length)
    throw new ArgumentException("Destination array is too small for the folder collection.");

Prevention

When it happens

Trigger: CopyTo called with an array allocated for fewer elements than the collection Count, or with an arrayIndex offset that pushes past the end of the array.

Common situations: Allocating the array before subfolders were created (Count grew); copying with a non-zero offset into a tightly-sized buffer.

Related errors


AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02). Data as JSON: /api/errors/c577477841eecb4f. Report an issue: GitHub.