aspnet / Mvc

[Archived] ASP.NET Core MVC is a model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
5.62k stars 2.14k forks source link

FormFileModelBinder infinite loop #8782

Closed janatjak closed 5 years ago

janatjak commented 5 years ago

Is this a Bug or Feature request?:

Bug

Steps to reproduce (preferably a link to a GitHub repo with a repro project):

Posting form with OneToMany structure containing IFormFile property e.g.:

public class QuestionEditViewModel
{
    public List<EditViewModel> Translations { get; set; }
}

public class EditViewModel
{
    public string Text { get; set; }
    public IFormFile UploadedFile { get; set; }
}

dotnet model binder jumps to never ending loop and generate new array items Translations[0].UploadedFile, Translations[1].UploadedFile, ... Translations[....never ending].UploadedFile,

Description of the problem:

Problem depends on commit 47d6d4e82cf94f3138a413571cfca6930d2018b9. https://github.com/aspnet/Mvc/blob/master/src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/Binders/FormFileModelBinder.cs#L89

Version of Microsoft.AspNetCore.Mvc or Microsoft.AspNetCore.App or Microsoft.AspNetCore.All:

Microsoft.AspNetCore.App 2.2.0

mkArtakMSFT commented 5 years ago

Thanks for contacting us, @janatjak. @dougbu, is this the same as: https://github.com/aspnet/Mvc/issues/8723 ?

dougbu commented 5 years ago

Yes, this matches #8723: Model binding system will iterate to int.MaxValue if model is a collection of a complex type and the complex type has a greedy binding source for one or more properties. The binding source for IFormFile is greedy.

dougbu commented 5 years ago

@mkArtakMSFT I suggest tracking this problem in #8723 and closing #8782 (this one) as a dupe. Agreed?