Skip to content

Commit 6175d14

Browse files
authored
Fixing infinite loop when using file stream as source (#386)
1 parent 81d3eed commit 6175d14

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

nanoFramework.System.Net.Http/Http/StreamContent.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,19 @@ protected override void SerializeToStream(Stream stream)
8181
byte[] buffer = new byte[2048];
8282
int read;
8383
int totalRead = 0;
84-
int contentLength = (int)Headers.ContentLength;
84+
long contentLength = Headers.ContentLength;
8585

8686
// occurrs when there is not Content_Length header (i.e. chunked response)
8787
if (contentLength < 0)
8888
{
89-
contentLength = int.MaxValue;
89+
if (TryComputeLength(out long possibleLength))
90+
{
91+
contentLength = possibleLength;
92+
}
93+
else
94+
{
95+
contentLength = int.MaxValue;
96+
}
9097
}
9198

9299
while (totalRead < contentLength)

0 commit comments

Comments
 (0)