Merge branch 'patch-1' of https://github.com/Romasz/Newtonsoft.Json into Romasz-patch-1
This commit is contained in:
@@ -4,4 +4,7 @@
|
|||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||||
</startup>
|
</startup>
|
||||||
|
<runtime>
|
||||||
|
<gcAllowVeryLargeObjects enabled="true"/>
|
||||||
|
</runtime>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -273,6 +273,46 @@ namespace Newtonsoft.Json.Tests.JsonTextReaderTests
|
|||||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ReadLargeObjects()
|
||||||
|
{
|
||||||
|
const int nrItems = 2;
|
||||||
|
const int length = int.MaxValue / 3;
|
||||||
|
|
||||||
|
byte apostrophe = Encoding.ASCII.GetBytes(@"""").First();
|
||||||
|
byte openingBracket = Encoding.ASCII.GetBytes(@"[").First();
|
||||||
|
byte comma = Encoding.ASCII.GetBytes(@",").First();
|
||||||
|
byte closingBracket = Encoding.ASCII.GetBytes(@"]").First();
|
||||||
|
|
||||||
|
using (MemoryStream ms = new MemoryStream())
|
||||||
|
{
|
||||||
|
ms.WriteByte(openingBracket);
|
||||||
|
for (int i = 0; i < nrItems; i++)
|
||||||
|
{
|
||||||
|
ms.WriteByte(apostrophe);
|
||||||
|
|
||||||
|
for (int j = 0; j <= length; j++)
|
||||||
|
ms.WriteByte(7);
|
||||||
|
|
||||||
|
ms.WriteByte(apostrophe);
|
||||||
|
if (i < nrItems - 1)
|
||||||
|
ms.WriteByte(comma);
|
||||||
|
}
|
||||||
|
ms.WriteByte(closingBracket);
|
||||||
|
ms.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
var reader = new JsonTextReader(new StreamReader(ms));
|
||||||
|
|
||||||
|
Assert.IsTrue(reader.Read());
|
||||||
|
|
||||||
|
for (int i = 0; i < nrItems; i++)
|
||||||
|
Assert.IsTrue(reader.Read());
|
||||||
|
|
||||||
|
Assert.IsTrue(reader.Read());
|
||||||
|
Assert.IsFalse(reader.Read());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ReadSingleBytes()
|
public void ReadSingleBytes()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -237,8 +237,9 @@ namespace Newtonsoft.Json
|
|||||||
{
|
{
|
||||||
// once in the last 10% of the buffer shift the remaining content to the start to avoid
|
// once in the last 10% of the buffer shift the remaining content to the start to avoid
|
||||||
// unnecessarily increasing the buffer size when reading numbers/strings
|
// unnecessarily increasing the buffer size when reading numbers/strings
|
||||||
|
//romasz: do it also if we are reading large objects that can cause the buffer's new length to exceed int.MaxValue
|
||||||
int length = _chars.Length;
|
int length = _chars.Length;
|
||||||
if (length - _charPos <= length * 0.1)
|
if (length - _charPos <= length * 0.1 || length > int.MaxValue / 2 - 1)
|
||||||
{
|
{
|
||||||
int count = _charsUsed - _charPos;
|
int count = _charsUsed - _charPos;
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user