Skip to content

.NET 10, ReadNextSectionAsync has bug,when postman submit single file throw System.IO.InvalidDataException:“The stream exceeded the data limit 16384.”, when postman submit 1+ files, ReadNextSectionAsync never return null。 #64696

@justmine2514

Description

@justmine2514

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

.NET 10, ReadNextSectionAsync has bug,when postman submit single file throw System.IO.InvalidDataException:“The stream exceeded the data limit 16384.”, when postman submit 1+ files, ReadNextSectionAsync never return null。

protected override async Task<IReadOnlyList?> HandleAsync(
HttpRequest request,
CancellationToken token = default)
{
if (!MediaTypeHeaderValue.TryParse(request.ContentType, out var mediaTypeHeader) ||
string.IsNullOrWhiteSpace(mediaTypeHeader.Boundary.Value))
throw HttpApiExceptions.BadRequest($"Content-Type is form-data, but boundary not found");
var boundary = HeaderUtilities.RemoveQuotes(mediaTypeHeader.Boundary).Value ?? throw HttpApiExceptions.BadRequest($"Content-Type is form-data, but boundary not found");
var reader = new MultipartReader(boundary, request.Body);
var section = await reader.ReadNextSectionAsync(token);
var hasWebBlob = false;
var storageOptions = BlobStorageService.Options;
var webBlobs = new Lazy<List>(() => new List(storageOptions.MaxFilesPerTime));
while (section != null)
{
var disposition = section.GetContentDispositionHeader();
if (disposition != null &&
disposition.IsFileDisposition() &&
!string.IsNullOrWhiteSpace(disposition.FileName.Value))
{
var fileSection = section.AsFileSection();
if (fileSection?.FileStream is null) continue;
var fileType = Path.GetExtension(disposition.FileName).ToString();
if (!storageOptions.IsFileTypePermitted(fileType))
throw HttpApiExceptions.BadRequest($"Illegal file type:{fileType}");
// handle file upload
}
// .NET 10, ReadNextSectionAsync has bug,when postman submit single file throw System.IO.InvalidDataException:“The stream exceeded the data limit 16384.”, when postman submit 1+ files, ReadNextSectionAsync never return null。
section = await reader.ReadNextSectionAsync(token);
}
return hasWebBlob ? webBlobs.Value : null;
}

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewares

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions