Skip to content

Commit 5472c23

Browse files
committed
update
1 parent 75d1bd2 commit 5472c23

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/Http/WebUtilities/src/MultipartBoundary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ internal sealed class MultipartBoundary
1010
private readonly byte[] _boundaryBytes;
1111
private bool _expectLeadingCrlf;
1212

13-
public MultipartBoundary(string boundary, bool expectLeadingCrlf = true)
13+
public MultipartBoundary(string boundary)
1414
{
1515
ArgumentNullException.ThrowIfNull(boundary);
1616

17-
_expectLeadingCrlf = expectLeadingCrlf;
17+
_expectLeadingCrlf = false;
1818
_boundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary);
1919

2020
FinalBoundaryLength = BoundaryBytes.Length + 2; // Include the final '--' terminator.

src/Http/WebUtilities/src/MultipartReader.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public MultipartReader(string boundary, Stream stream, int bufferSize)
5656
}
5757
_stream = new BufferedReadStream(stream, bufferSize);
5858
boundary = HeaderUtilities.RemoveQuotes(new StringSegment(boundary)).ToString();
59-
_boundary = new MultipartBoundary(boundary, false);
59+
_boundary = new MultipartBoundary(boundary);
6060
}
6161

6262
/// <summary>
@@ -83,12 +83,9 @@ public MultipartReader(string boundary, Stream stream, int bufferSize)
8383
/// <returns></returns>
8484
public async Task<MultipartSection?> ReadNextSectionAsync(CancellationToken cancellationToken = new CancellationToken())
8585
{
86-
if (_currentStream == null)
87-
{
88-
// Only occurs on first call
89-
// This stream will drain any preamble data and remove the first boundary marker.
90-
_currentStream = new MultipartReaderStream(_stream, _boundary) { LengthLimit = HeadersLengthLimit };
91-
}
86+
// Only occurs on first call
87+
// This stream will drain any preamble data and remove the first boundary marker.
88+
_currentStream ??= new MultipartReaderStream(_stream, _boundary) { LengthLimit = HeadersLengthLimit };
9289

9390
// Drain the prior section.
9491
await _currentStream.DrainAsync(cancellationToken);

src/Http/WebUtilities/src/MultipartReaderStream.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,18 @@ private int UpdatePosition(int read)
145145
if (_observedLength < _position)
146146
{
147147
_observedLength = _position;
148-
if (LengthLimit.HasValue && _observedLength > LengthLimit.GetValueOrDefault())
148+
if (LengthLimit.HasValue &&
149+
LengthLimit.GetValueOrDefault() is var lengthLimit &&
150+
_observedLength > lengthLimit)
149151
{
150152
// If we hit the limit before the first boundary then we're using the header length limit, not the body length limit.
151153
if (_boundary.BeforeFirstBoundary())
152154
{
153-
throw new InvalidDataException($"Multipart header length limit {LengthLimit.GetValueOrDefault()} exceeded. Too much data before the first boundary.");
155+
throw new InvalidDataException($"Multipart header length limit {lengthLimit} exceeded. Too much data before the first boundary.");
154156
}
155157
else
156158
{
157-
throw new InvalidDataException($"Multipart body length limit {LengthLimit.GetValueOrDefault()} exceeded.");
159+
throw new InvalidDataException($"Multipart body length limit {lengthLimit} exceeded.");
158160
}
159161
}
160162
}

0 commit comments

Comments
 (0)