dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.47k stars 10.03k forks source link

Line length limit 100 exceeded on multipart form request #2939

Closed richardhopton closed 5 years ago

richardhopton commented 6 years ago

When making the following request on my mac: -

curl -X POST \
  http://localhost:8080/upload \
  -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryRiOPcOCObfAkq1Aw' \
  -d '------WebKitFormBoundaryRiOPcOCObfAkq1Aw
Content-Disposition: form-data; name="uid"

1252154297730234145_18808100
------WebKitFormBoundaryRiOPcOCObfAkq1Aw
Content-Disposition: form-data; name="label"

interior
------WebKitFormBoundaryRiOPcOCObfAkq1Aw--'

Against the following controller method: -

[HttpPost]
public async Task<IActionResult> UploadAsync()
{
    if (!Request.ContentType.StartsWith("multipart/"))
        return BadRequest();

    var form = Request.Form;

    return Ok(form.Count);
}

I receive the following response: -

{"status":"Failure","errors":[{"code":"InternalServerError","exceptionMessage":"Line length limit 100 exceeded."}]}

If I wrap the Request.Form access in a try catch the following exception stack trace is throw: -

{System.IO.InvalidDataException: Line length limit 100 exceeded.
   at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.<ReadLineAsync>d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.<ReadAsync>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.<DrainAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.WebUtilities.MultipartReader.<ReadNextSectionAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.Http.Features.FormFeature.<InnerReadFormAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm()
   at Microsoft.AspNetCore.Http.Internal.DefaultHttpRequest.get_Form()
   at FileUploadTest.Controllers.UploadController.<UploadAsync>d__4.MoveNext() in /Users/richard/Source/file-upload-test/src/service/Controllers/UploadController.cs:line 50}
richardhopton commented 6 years ago

After debugging the bytes of the incoming request Body, it only has new line characters and no carriage returns which BufferedReadStream requires to delimiter lines. It sounds like this needs to be changed.

danielmeza commented 6 years ago

Any update on this? I got this error to.

Tratcher commented 6 years ago

That format is invalid, what client is sending it?

danielmeza commented 6 years ago

@Tratcher I'm with .NET Framework and reciving in a asp.net core site, the library is from nuget, we fix the issue, it wast related to the result of the query from the db, we compress and aencrypt the result from the query and send it through http, we solved by ading some missing CRLF

Tratcher commented 6 years ago

?? What software is sending invalid multipart requests to your server?

danielmeza commented 6 years ago

@Tratcher a console app is reading datta from DB2 using oledb

Tratcher commented 6 years ago

I don't understand how DB2 relates to sending a multipart message. You're going to need to supply some sample code, preferrably as a runnable github repo.

analogrelay commented 5 years ago

Closing this as we haven't heard from you. Please feel free to comment if you're able to get the information we're looking for and we can reopen the issue if we're able to identify the problem.