mirror of
https://github.com/Tencent/rapidjson.git
synced 2025-10-28 11:31:57 +01:00
Fix MemoryStream::Peek() and add test for fix
MemoryStream::Peek() did not return '\0' if src_ == end_, but Peek() == '\0' is used in parsing in the GenericReader. Without this change, parsing with MemoryStream as the InputStream could result in a segmentation fault.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "unittest.h"
|
||||
|
||||
#include "rapidjson/reader.h"
|
||||
#include "rapidjson/memorystream.h"
|
||||
|
||||
using namespace rapidjson;
|
||||
|
||||
@@ -674,6 +675,15 @@ TEST(Reader, ParseObject_Error) {
|
||||
|
||||
// Must be a comma or '}' after an object member
|
||||
TEST_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, "{\"a\":1]");
|
||||
|
||||
// This tests that MemoryStream is checking the length in Peek().
|
||||
{
|
||||
MemoryStream ms("{\"a\"", 1);
|
||||
BaseReaderHandler<> h;
|
||||
Reader reader;
|
||||
EXPECT_FALSE(reader.Parse<kParseStopWhenDoneFlag>(ms, h));
|
||||
EXPECT_EQ(kParseErrorObjectMissName, reader.GetParseErrorCode());
|
||||
}
|
||||
}
|
||||
|
||||
#undef TEST_ERROR
|
||||
|
||||
Reference in New Issue
Block a user