peass-ng/PEASS-ng · error · ArgumentException

Array index must be 0 or greater.

Error message

Array index must be 0 or greater.

What it means

ICollection<NameValuePair>.CopyTo rejects a negative arrayIndex with ArgumentException ('Array index must be 0 or greater.'). A negative start offset is meaningless for a copy operation, so the at-fault input is the negative index argument supplied by the caller.

Source

Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/NamedValueCollection.cs:542

        {
            if (v2Coll == null)
                return unboundDict.Contains(item);

            foreach (var invp in this)
                if (Equals(item, invp)) return true;
            return false;
        }

        void ICollection<NameValuePair>.CopyTo(NameValuePair[] array, int arrayIndex)
        {
            if (v2Coll == null)
                unboundDict.CopyTo(array, arrayIndex);
            else
            {
                if (array.Length - arrayIndex < v2Coll.Count)
                    throw new ArgumentException("Items in collection exceed available items in destination array.");
                if (arrayIndex < 0)
                    throw new ArgumentException(@"Array index must be 0 or greater.", nameof(arrayIndex));
                for (var i = 0; i < v2Coll.Count; i++)
                    array[i + arrayIndex] = new NameValuePair(v2Coll[i]);
            }
        }

        bool ICollection<NameValuePair>.IsReadOnly => false;

        ICollection<string> IDictionary<string, string>.Keys => Names;

        bool ICollection<KeyValuePair<string, string>>.IsReadOnly => false;

        bool ICollection<NameValuePair>.Remove(NameValuePair item)
        {
            var i = -1;
            try
            {
                if (v2Coll == null)
                {

View on GitHub (pinned to 53fb989abc)

Solutions

  1. Clamp or validate arrayIndex >= 0 before calling CopyTo.
  2. Pass 0 as arrayIndex when copying into a freshly allocated array.
  3. Fix the upstream computation that produced the negative offset.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/NamedValueCollection.cs:542 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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