-Fixed infinite loop from an input error when reading an array and error handling is catching the error

-Fixed base object error not being handled when deserializing
This commit is contained in:
James Newton-King
2012-04-28 01:41:56 +12:00
parent d63e662bda
commit a0fd6bb3e0
5 changed files with 196 additions and 10 deletions
+23 -1
View File
@@ -55,6 +55,7 @@ namespace Newtonsoft.Json
private const char UnicodeReplacementChar = '\uFFFD';
private readonly TextReader _reader;
private int _readerFailureCount;
private char[] _chars;
private int _charsUsed;
@@ -75,6 +76,8 @@ namespace Newtonsoft.Json
throw new ArgumentNullException("reader");
_reader = reader;
_readerFailureCount = 0;
_lineNumber = 1;
_chars = new char[4097];
@@ -323,7 +326,26 @@ namespace Newtonsoft.Json
int attemptCharReadCount = _chars.Length - _charsUsed - 1;
int charsRead = _reader.Read(_chars, _charsUsed, attemptCharReadCount);
int charsRead;
try
{
charsRead = _reader.Read(_chars, _charsUsed, attemptCharReadCount);
_readerFailureCount = 0;
}
catch
{
// to prevent infinate loop when error handling is enabled
if (!_isEndOfFile)
{
_readerFailureCount++;
if (_readerFailureCount >= 3)
_isEndOfFile = true;
}
throw;
}
_charsUsed += charsRead;
if (charsRead == 0)