{"record":{"id":"241c59475cfac507","repo":"dotnet/wpf","slug":"args","errorCode":null,"errorMessage":"args","messagePattern":"args","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/PageCache.cs","lineNumber":362,"sourceCode":"            if (_isPaginationCompleted)\n            {\n                if (args.Start == 0)\n                {\n                    //Since we've started repaginating from the beginning of the document\n                    //after pagination was completed, we can't assume we know\n                    //the default page size anymore.\n                    _isDefaultSizeKnown = false;\n                    _dynamicPageSizes = false;\n                }\n\n                //Reset our IsPaginationCompleted flag since we just got a pagination event.\n                _isPaginationCompleted = false;\n            }\n\n            //Check for integer overflow.\n            if (args.Start + args.Count < 0)\n            {\n                throw new ArgumentOutOfRangeException(\"args\");\n            }\n\n            //Create our list of changes.  We allocate space for 2 changes here\n            //as we can have as many as two changes resulting from a Pagination event.\n            List<PageCacheChange> changes = new List<PageCacheChange>(2);\n            PageCacheChange change;\n\n            //If we have pages to add or modify, do so now.\n            if (args.Count > 0)\n            {\n                //If pagination has added new pages onto the end of the document, we\n                //add new entries to our cache.\n                if (args.Start >= _cache.Count)\n                {\n                    //Completely new pages, so we add new cache entries\n                    change = AddRange(args.Start, args.Count);\n                    if (change != null)\n                    {","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/PageCache.cs#L344-L380","documentation":"PageCache.PaginationProgressDelegate checks the incoming PaginationProgressEventArgs for integer overflow: if args.Start + args.Count is negative (negative Start and/or Count combining below zero), it throws ArgumentOutOfRangeException(\"args\"). This protects the page-change computation from corrupting page cache indices.","triggerScenarios":"A paginator reports a PaginationProgress event whose Start + Count is negative (negative Start, negative Count, or their sum below 0) when PageCache processes it on the dispatcher.","commonSituations":"Custom DocumentPaginator implementations raising PaginationProgressEventArgs with incorrect Start/Count values (e.g. negative Start after re-pagination or content shrinkage).","solutions":["Fix the custom DocumentPaginator so PaginationProgressEventArgs has Start >= 0, Count >= 0, and a non-negative sum.","Validate Start/Count before raising OnPaginationProgress in your paginator subclass.","Clamp Start to >= 0 and never report a range ending below 0.","For built-in paginators, apply .NET servicing updates or report the bug."],"exampleFix":"// before\nOnPaginationProgress(this, new PaginationProgressEventArgs(lastKnownStart - delta, count));\n\n// after\nint start = Math.Max(0, lastKnownStart - delta);\nOnPaginationProgress(this, new PaginationProgressEventArgs(start, count));","handlingStrategy":"validation","validationCode":"void SafeOnPaginationProgress(int start, int count)\n{\n    if (start < 0 || count < 0 || start + count < 0)\n        throw new ArgumentOutOfRangeException(nameof(start));\n    OnPaginationProgress(this, new PaginationProgressEventArgs(start, count));\n}","typeGuard":"static bool IsValidProgressRange(PaginationProgressEventArgs a) => a != null && a.Start >= 0 && a.Count >= 0 && a.Start + a.Count >= 0;","tryCatchPattern":"try { paginator.OnPaginationProgress(this, args); }\ncatch (ArgumentOutOfRangeException) { /* fix Start/Count before re-raising */ }","preventionTips":["In custom DocumentPaginators, never raise PaginationProgress with negative Start/Count.","Clamp Start to >= 0 after content shrinkage or re-pagination.","Unit-test paginator progress ranges against overflow combinations."],"tags":["wpf","pagination","argument-out-of-range","overflow"],"backgroundTag":"argument-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}