aspnet / KestrelHttpServer

[Archived] A cross platform web server for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
2.63k stars 528 forks source link

InvalidDataException: Line length limit 100 exceeded #3057

Closed thomasd3 closed 5 years ago

thomasd3 commented 5 years ago

When uploading data files with RestSharp to a .Net Core 2.1 REST interface, I get this error on some files:

System.IO.InvalidDataException: Line length limit 100 exceeded.
   at Microsoft.AspNetCore.WebUtilities.BufferedReadStream.ReadLineAsync(Int32 lengthLimit, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool`1 bytePool, Nullable`1 limit, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.MultipartReader.ReadNextSectionAsync(CancellationToken cancellationToken)

When I do the same operation with Insomnia, I do not get any error, only with RestSharp.

I have read here https://stackoverflow.com/questions/44642701/microsoft-aspnetcore-webutilities-line-length-limit-100-exceeded that there is a problem with the line ending formats, but this is the only article about it.

The controller signature is very simple:

[HttpPost, DisableRequestSizeLimit]
public async Task<IActionResult> AddPictureAsync(
    IFormFile Picture,
    IFormFile Thumbnail,
    string Title)
{

and the code to send is:

var Request = new RestRequest("picture", Method.POST) { AlwaysMultipartFormData = true };
Request.AddHeader("SessionId", SessionId);
Request.AddFile("Picture", PhotoData.ToArray(), Photo.PhotoUrl);
Request.AddFile("Thumbnail", ThumbnailData, Photo.PhotoUrl.Replace(".jpg", "-t.jpg"));
Request.AddParameter("Title", Photo.Title ?? string.Empty, ParameterType.GetOrPost);

If I understand the error, it means that the data lines are longer than they should. But is there a way to inspect what is coming in? My controller doesn't even get executed, the error happens before

Tratcher commented 5 years ago

This issue was moved to aspnet/AspNetCore#3724