{"record":{"id":"948c301b566d6a8a","repo":"peass-ng/PEASS-ng","slug":"specified-argument-was-out-of-the-range-of-valid-v-948c30","errorCode":null,"errorMessage":"Specified argument was out of the range of valid values. (Parameter 'arrayIndex')","messagePattern":"Specified argument was out of the range of valid values\\. \\(Parameter 'arrayIndex'\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs","lineNumber":116,"sourceCode":"            {\n                for (var i = v2FolderList.Count; i > 0; i--)\n                    if (string.Equals(item.Path, v2FolderList[i].Path, StringComparison.CurrentCultureIgnoreCase))\n                        return true;\n            }\n            else\n                return item.Path == \"\\\\\";\n            return false;\n        }\n\n        /// <summary>Copies the elements of the ICollection to an Array, starting at a particular Array index.</summary>\n        /// <param name=\"array\">\n        /// The one-dimensional Array that is the destination of the elements copied from <see cref=\"ICollection{T}\"/>. The Array must have\n        /// zero-based indexing.\n        /// </param>\n        /// <param name=\"arrayIndex\">The zero-based index in array at which copying begins.</param>\n        public void CopyTo(TaskFolder[] array, int arrayIndex)\n        {\n            if (arrayIndex < 0) throw new ArgumentOutOfRangeException(nameof(arrayIndex));\n            if (array == null) throw new ArgumentNullException(nameof(array));\n            if (v2FolderList != null)\n            {\n                if (arrayIndex + Count > array.Length)\n                    throw new ArgumentException();\n                foreach (var f in this)\n                    array[arrayIndex++] = f;\n            }\n            else\n            {\n                if (arrayIndex + v1FolderList.Length > array.Length)\n                    throw new ArgumentException();\n                v1FolderList.CopyTo(array, arrayIndex);\n            }\n        }\n\n        /// <summary>Releases all resources used by this class.</summary>\n        public void Dispose()","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/TaskFolderCollection.cs#L98-L134","documentation":"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.","triggerScenarios":"Calling CopyTo(array, -1) or passing an index computed from a failed search/offset that ended up negative.","commonSituations":"Copying SubFolders into a preallocated array with an off-by-one or uninitialized index variable.","solutions":["Ensure arrayIndex >= 0 before calling CopyTo","Prefer enumerating the collection with foreach instead of CopyTo","Use ToArray()/ToList() style copying via LINQ"],"exampleFix":"// before\nint idx = folders.Select(f => f.Name).ToList().IndexOf(\"x\") - 1;\nsubFolders.CopyTo(arr, idx);\n// after\nif (idx >= 0 && idx < arr.Length) subFolders.CopyTo(arr, idx);","handlingStrategy":"validation","validationCode":"if (array == null || arrayIndex < 0 || array.Length - arrayIndex < subFolders.Count)\n    throw new ArgumentException(\"Destination array too small or invalid index.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Assert arrayIndex >= 0 before CopyTo","Prefer foreach or ToArray() over manual CopyTo","Keep index arithmetic (offsets) in one validated helper"],"tags":["task-scheduler","argumentoutofrange","copyto"],"backgroundTag":"array-index-out-of-range","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}