Skip to content

Model binding infinite recursion or infinite loop with complex collections #7052

@dougbu

Description

@dougbu

Describe the bug

Collections of complex types may bind unconditionally until int.MaxValue elements are reached. This relates to #4939 but involves built-in model binders.

Similarly, nested types may recursively bind until the stack is exhausted. This may relate to #6616.

To Reproduce

Steps to reproduce the behavior:

  1. Using the current version of ASP.NET Core i.e. master
  2. Create a simple model such as
    private class LocationInfo
    {
        [FromHeader]
        public string GpsCoordinates { get; set; }
    
        public int Zipcode { get; set; }
    }
  3. Add an action to a controller or a handler to a page with a List<LocationInfo> argument
  4. Post a request containing a `` header to the action
  5. Experience extremely slow response (as the collection fills up int.MaxValue items

Expected behavior

Expect model binding to detect the problem and throw an Exception informing the developer.

Additional context

Beyond [FromHeader], the problem may occur with [FromServices] or a custom greedy model binder. It's possible other models can cause infinite recursion or extremely large collections in model binding.

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-model-binding

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions