mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 03:22:14 +00:00
Fix hdfs crash
This commit is contained in:
parent
e2249bf1e5
commit
1993d8e0f4
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user