From 3e89cd95b8b0b2a0cce9b691a94f783159d987fb Mon Sep 17 00:00:00 2001 From: Kaijie Chen Date: Fri, 13 Sep 2024 15:05:13 +0800 Subject: [PATCH 1/2] [fix](stream-load) catch exception when parsing CONTENT_LENGTH --- be/src/http/action/http_stream.cpp | 14 ++++++++++++-- be/src/http/action/stream_load.cpp | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/be/src/http/action/http_stream.cpp b/be/src/http/action/http_stream.cpp index c6176c52815459..ee23e235bed5ef 100644 --- a/be/src/http/action/http_stream.cpp +++ b/be/src/http/action/http_stream.cpp @@ -197,7 +197,12 @@ Status HttpStreamAction::_on_header(HttpRequest* http_req, std::shared_ptrbody_bytes = 0; size_t csv_max_body_bytes = config::streaming_load_max_mb * 1024 * 1024; if (!http_req->header(HttpHeaders::CONTENT_LENGTH).empty()) { - ctx->body_bytes = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); + try { + ctx->body_bytes = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); + } catch (const std::exception& e) { + return Status::InvalidArgument("invalid HTTP header CONTENT_LENGTH={}: {}", + http_req->header(HttpHeaders::CONTENT_LENGTH), e.what()); + } // csv max body size if (ctx->body_bytes > csv_max_body_bytes) { LOG(WARNING) << "body exceed max size." << ctx->brief(); @@ -352,7 +357,12 @@ Status HttpStreamAction::process_put(HttpRequest* http_req, // FIXME find a way to avoid chunked stream load write large WALs size_t content_length = 0; if (!http_req->header(HttpHeaders::CONTENT_LENGTH).empty()) { - content_length = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); + try { + content_length = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); + } catch (const std::exception& e) { + return Status::InvalidArgument("invalid HTTP header CONTENT_LENGTH={}: {}", + http_req->header(HttpHeaders::CONTENT_LENGTH), e.what()); + } if (ctx->format == TFileFormatType::FORMAT_CSV_GZ || ctx->format == TFileFormatType::FORMAT_CSV_LZO || ctx->format == TFileFormatType::FORMAT_CSV_BZ2 || diff --git a/be/src/http/action/stream_load.cpp b/be/src/http/action/stream_load.cpp index 1a9420dea637db..29d57760bbe577 100644 --- a/be/src/http/action/stream_load.cpp +++ b/be/src/http/action/stream_load.cpp @@ -266,7 +266,12 @@ Status StreamLoadAction::_on_header(HttpRequest* http_req, std::shared_ptrheader(HttpHeaders::CONTENT_LENGTH).empty()) { - ctx->body_bytes = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); + try { + ctx->body_bytes = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); + } catch (const std::exception& e) { + return Status::InvalidArgument("invalid HTTP header CONTENT_LENGTH={}: {}", + http_req->header(HttpHeaders::CONTENT_LENGTH), e.what()); + } // json max body size if ((ctx->format == TFileFormatType::FORMAT_JSON) && (ctx->body_bytes > json_max_body_bytes) && !read_json_by_line) { @@ -671,7 +676,12 @@ Status StreamLoadAction::_process_put(HttpRequest* http_req, // FIXME find a way to avoid chunked stream load write large WALs size_t content_length = 0; if (!http_req->header(HttpHeaders::CONTENT_LENGTH).empty()) { - content_length = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); + try { + content_length = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); + } catch (const std::exception& e) { + return Status::InvalidArgument("invalid HTTP header CONTENT_LENGTH={}: {}", + http_req->header(HttpHeaders::CONTENT_LENGTH), e.what()); + } if (ctx->format == TFileFormatType::FORMAT_CSV_GZ || ctx->format == TFileFormatType::FORMAT_CSV_LZO || ctx->format == TFileFormatType::FORMAT_CSV_BZ2 || From 6af3b268af73aeec4a7b642eb03b28173d7fdd0b Mon Sep 17 00:00:00 2001 From: Kaijie Chen Date: Fri, 13 Sep 2024 15:08:43 +0800 Subject: [PATCH 2/2] fix style --- be/src/http/action/http_stream.cpp | 3 ++- be/src/http/action/stream_load.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/be/src/http/action/http_stream.cpp b/be/src/http/action/http_stream.cpp index ee23e235bed5ef..4a34605aa336a1 100644 --- a/be/src/http/action/http_stream.cpp +++ b/be/src/http/action/http_stream.cpp @@ -361,7 +361,8 @@ Status HttpStreamAction::process_put(HttpRequest* http_req, content_length = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); } catch (const std::exception& e) { return Status::InvalidArgument("invalid HTTP header CONTENT_LENGTH={}: {}", - http_req->header(HttpHeaders::CONTENT_LENGTH), e.what()); + http_req->header(HttpHeaders::CONTENT_LENGTH), + e.what()); } if (ctx->format == TFileFormatType::FORMAT_CSV_GZ || ctx->format == TFileFormatType::FORMAT_CSV_LZO || diff --git a/be/src/http/action/stream_load.cpp b/be/src/http/action/stream_load.cpp index 29d57760bbe577..eef6a27b626539 100644 --- a/be/src/http/action/stream_load.cpp +++ b/be/src/http/action/stream_load.cpp @@ -680,7 +680,8 @@ Status StreamLoadAction::_process_put(HttpRequest* http_req, content_length = std::stol(http_req->header(HttpHeaders::CONTENT_LENGTH)); } catch (const std::exception& e) { return Status::InvalidArgument("invalid HTTP header CONTENT_LENGTH={}: {}", - http_req->header(HttpHeaders::CONTENT_LENGTH), e.what()); + http_req->header(HttpHeaders::CONTENT_LENGTH), + e.what()); } if (ctx->format == TFileFormatType::FORMAT_CSV_GZ || ctx->format == TFileFormatType::FORMAT_CSV_LZO ||