Merge branch 'read_query_body_fix' of https://github.com/silviucpp/ClickHouse into silviucpp-read_query_body_fix

This commit is contained in:
Nikolai Kochetov 2018-03-26 21:30:15 +03:00
commit 0d3ee2e07b

View File

@ -415,23 +415,30 @@ void executeQuery(
if (istr.buffer().size() == 0)
istr.next();
size_t max_query_size = context.getSettingsRef().max_query_size;
size_t bytes_copied = 0;
if (istr.buffer().end() - istr.position() >= static_cast<ssize_t>(max_query_size))
do
{
/// If remaining buffer space in 'istr' is enough to parse query up to 'max_query_size' bytes, then parse inplace.
begin = istr.position();
end = istr.buffer().end();
istr.position() += end - begin;
}
else
{
/// If not - copy enough data into 'parse_buf'.
parse_buf.resize(max_query_size);
parse_buf.resize(istr.read(&parse_buf[0], max_query_size));
begin = &parse_buf[0];
end = begin + parse_buf.size();
ssize_t buffer_size = istr.buffer().end() - istr.position();
if(buffer_size == 0)
break;
size_t new_size = bytes_copied + buffer_size;
//should we protect here against malicious code ? checking for max_query_size seems not ok as
//time for inserts the values are ignored
//size_t max_query_size = context.getSettingsRef().max_query_size;
//if(max_query_size && new_size > max_query_size)
// throw Exception("Query is too large exceeding max_query_size of " + toString(max_query_size), ErrorCodes::QUERY_IS_TOO_LARGE);
parse_buf.resize(new_size);
bytes_copied += istr.read(&parse_buf[bytes_copied], buffer_size);
}
while(istr.next());
begin = &parse_buf[0];
end = begin + bytes_copied;
ASTPtr ast;
BlockIO streams;