IMPALA-5541: Reject BATCH_SIZE greater than 65536 Setting a very large value could cause strange behaviour like crashing, hanging, excessive memory usage, spinning etc. This patch rejects values out of the range [0,65536].
Change-Id: Idd5a2490a73b6915224160d7604b4badc72c1d97 Reviewed-on: http://gerrit.cloudera.org:8080/8419 Reviewed-by: Tim Armstrong <[email protected]> Tested-by: Impala Public Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/98490925 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/98490925 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/98490925 Branch: refs/heads/master Commit: 98490925cb0dc05e46c437ea3b88fbd1f02b8f52 Parents: 76111ce Author: Tianyi Wang <[email protected]> Authored: Fri Oct 27 17:20:08 2017 -0700 Committer: Impala Public Jenkins <[email protected]> Committed: Thu Nov 2 00:45:11 2017 +0000 ---------------------------------------------------------------------- be/src/service/query-options-test.cc | 3 ++- be/src/service/query-options.cc | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/98490925/be/src/service/query-options-test.cc ---------------------------------------------------------------------- diff --git a/be/src/service/query-options-test.cc b/be/src/service/query-options-test.cc index e617ef2..efc5307 100644 --- a/be/src/service/query-options-test.cc +++ b/be/src/service/query-options-test.cc @@ -223,7 +223,8 @@ TEST(QueryOptions, SetIntOptions) { {MAKE_OPTIONDEF(runtime_filter_wait_time_ms), {0, I32_MAX}}, {MAKE_OPTIONDEF(mt_dop), {0, 64}}, {MAKE_OPTIONDEF(disable_codegen_rows_threshold), {0, I32_MAX}}, - {MAKE_OPTIONDEF(max_num_runtime_filters), {0, I32_MAX}} + {MAKE_OPTIONDEF(max_num_runtime_filters), {0, I32_MAX}}, + {MAKE_OPTIONDEF(batch_size), {0, 65536}} }; for (const auto& test_case : case_set) { const OptionDef<int32_t>& option_def = test_case.first; http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/98490925/be/src/service/query-options.cc ---------------------------------------------------------------------- diff --git a/be/src/service/query-options.cc b/be/src/service/query-options.cc index 047a8a2..740654a 100644 --- a/be/src/service/query-options.cc +++ b/be/src/service/query-options.cc @@ -148,9 +148,17 @@ Status impala::SetQueryOption(const string& key, const string& value, query_options->__set_disable_codegen( iequals(value, "true") || iequals(value, "1")); break; - case TImpalaQueryOptions::BATCH_SIZE: - query_options->__set_batch_size(atoi(value.c_str())); + case TImpalaQueryOptions::BATCH_SIZE: { + StringParser::ParseResult status; + int val = StringParser::StringToInt<int>(value.c_str(), + static_cast<int>(value.size()), &status); + if (status != StringParser::PARSE_SUCCESS || val < 0 || val > 65536) { + return Status(Substitute("Invalid batch size '$0'. Valid sizes are in" + "[0, 65536]", value)); + } + query_options->__set_batch_size(val); break; + } case TImpalaQueryOptions::MEM_LIMIT: { // Parse the mem limit spec and validate it. int64_t bytes_limit;
