Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Http/WebUtilities/src/MultipartReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNetCore.WebUtilities;

Expand Down Expand Up @@ -61,6 +62,7 @@ public MultipartReader(string boundary, Stream stream, int bufferSize)
throw new ArgumentOutOfRangeException(nameof(bufferSize), bufferSize, "Insufficient buffer space, the buffer must be larger than the boundary: " + boundary);
}
_stream = new BufferedReadStream(stream, bufferSize);
boundary = HeaderUtilities.RemoveQuotes(new StringSegment(boundary)).ToString();
_boundary = new MultipartBoundary(boundary, false);
// This stream will drain any preamble data and remove the first boundary marker.
// TODO: HeadersLengthLimit can't be modified until after the constructor.
Expand Down
12 changes: 12 additions & 0 deletions src/Http/WebUtilities/test/MultipartReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.WebUtilities;
public class MultipartReaderTests
{
private const string Boundary = "9051914041544843365972754266";
private const string BoundaryWithQuotes = @"""9051914041544843365972754266""";
// Note that CRLF (\r\n) is required. You can't use multi-line C# strings here because the line breaks on Linux are just LF.
private const string OnePartBody =
"--9051914041544843365972754266\r\n" +
Expand Down Expand Up @@ -377,4 +378,15 @@ public async Task MultipartReader_ReadInvalidUtf8SurrogateHeader_ReplacementChar

Assert.Null(await reader.ReadNextSectionAsync());
}

// MultiPartReader should strip any quotes from the boundary passed in instead of throwing an exception
[Fact]
public async Task MultipartReader_StripQuotesFromBoundary()
{
var stream = MakeStream(OnePartBody);
var reader = new MultipartReader(BoundaryWithQuotes, stream);

var section = await reader.ReadNextSectionAsync();
Assert.NotNull(section);
}
}