Fix hdfs crash

This commit is contained in:
kssenii 2021-07-14 14:59:06 +03:00
parent e2249bf1e5
commit 1993d8e0f4
2 changed files with 16 additions and 0 deletions

View File

@ -29,10 +29,12 @@ std::pair<bool, size_t> fileSegmentationEngineJSONEachRowImpl(ReadBuffer & in, D
if (quotes)
{
pos = find_first_symbols<'\\', '"'>(pos, in.buffer().end());
if (pos > in.buffer().end())
throw Exception("Position in buffer is out of bounds. There must be a bug.", ErrorCodes::LOGICAL_ERROR);
else if (pos == in.buffer().end())
continue;
if (*pos == '\\')
{
++pos;
@ -48,10 +50,12 @@ std::pair<bool, size_t> fileSegmentationEngineJSONEachRowImpl(ReadBuffer & in, D
else
{
pos = find_first_symbols<'{', '}', '\\', '"'>(pos, in.buffer().end());
if (pos > in.buffer().end())
throw Exception("Position in buffer is out of bounds. There must be a bug.", ErrorCodes::LOGICAL_ERROR);
else if (pos == in.buffer().end())
continue;
else if (*pos == '{')
{
++balance;

View File

@ -351,9 +351,16 @@ static ReturnType parseJSONEscapeSequence(Vector & s, ReadBuffer & buf)
};
++buf.position();
/// It is possible that current buffer ends with `\` (start of escape sequence), oef is not reached,
/// but there is no pending data yet. Without this wait we will read beyond the end of current buffer in code below.
while (!buf.eof() && !buf.hasPendingData()) {}
if (buf.eof())
return error("Cannot parse escape sequence", ErrorCodes::CANNOT_PARSE_ESCAPE_SEQUENCE);
assert(buf.hasPendingData());
switch (*buf.position())
{
case '"':
@ -1124,10 +1131,13 @@ void saveUpToPosition(ReadBuffer & in, DB::Memory<> & memory, char * current)
const size_t old_bytes = memory.size();
const size_t additional_bytes = current - in.position();
const size_t new_bytes = old_bytes + additional_bytes;
/// There are no new bytes to add to memory.
/// No need to do extra stuff.
if (new_bytes == 0)
return;
assert(in.position() + additional_bytes <= in.buffer().end());
memory.resize(new_bytes);
memcpy(memory.data() + old_bytes, in.position(), additional_bytes);
in.position() = current;
@ -1140,6 +1150,8 @@ bool loadAtPosition(ReadBuffer & in, DB::Memory<> & memory, char * & current)
if (current < in.buffer().end())
return true;
while (!in.eof() && !in.hasPendingData()) {}
saveUpToPosition(in, memory, current);
bool loaded_more = !in.eof();