Skip to content

Commit ecb0b77

Browse files
authored
fix a bug in s3 where more data could be written to a stream than requested size (introduced by system.text.json pooling (#3637)
1 parent 6046679 commit ecb0b77

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

sdk/src/Services/S3/Custom/Transfer/Internal/_async/MultipartUploadCommand.async.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ private void AbortMultipartUpload(string uploadId)
214214
long minPartSize = request?.PartSize != 0 ? request.PartSize : S3Constants.MinPartSize;
215215
var uploadPartResponses = new List<UploadPartResponse>();
216216
var readBuffer = ArrayPool<byte>.Shared.Rent(READ_BUFFER_SIZE);
217-
var partBuffer = ArrayPool<byte>.Shared.Rent((int)minPartSize + (READ_BUFFER_SIZE));
218-
217+
var partBuffer = ArrayPool<byte>.Shared.Rent((int)minPartSize + readBuffer.Length);
218+
219219
MemoryStream nextUploadBuffer = new MemoryStream(partBuffer);
220220
using (var stream = request.InputStream)
221221
{
@@ -232,7 +232,6 @@ private void AbortMultipartUpload(string uploadId)
232232
// read the stream ahead and process it in the next iteration.
233233
// this is used to set isLastPart when there is no data left in the stream.
234234
readAheadBytesCount = await stream.ReadAsync(readBuffer, 0, readBuffer.Length).ConfigureAwait(false);
235-
236235
if ((nextUploadBuffer.Position > minPartSize || readAheadBytesCount == 0))
237236
{
238237
if (nextUploadBuffer.Position == 0)

0 commit comments

Comments
 (0)