Skip to content

Commit a1910e4

Browse files
authored
[fix](be) Validate stream load content length before group commit (#62110)
Group commit pre-check parsed Content-Length before the normal request validation path, so malformed values could escape the expected InvalidArgument handling. - Add try/catch around Content-Length parsing in _can_group_commit() to return Status::InvalidArgument on malformed values. - Preserve existing negative-length handling while preventing std::stoll exceptions from escaping. - Cache the Content-Length header while validating group commit requests to avoid repeated lookups.
1 parent 9e3d1f3 commit a1910e4

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

be/src/service/http/action/stream_load.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -915,9 +915,16 @@ Status StreamLoadAction::_check_wal_space(const std::string& group_commit_mode,
915915
Status StreamLoadAction::_can_group_commit(HttpRequest* req, std::shared_ptr<StreamLoadContext> ctx,
916916
std::string& group_commit_header,
917917
bool& can_group_commit) {
918-
int64_t content_length = req->header(HttpHeaders::CONTENT_LENGTH).empty()
919-
? 0
920-
: std::stoll(req->header(HttpHeaders::CONTENT_LENGTH));
918+
int64_t content_length = 0;
919+
const auto& content_length_str = req->header(HttpHeaders::CONTENT_LENGTH);
920+
if (!content_length_str.empty()) {
921+
try {
922+
content_length = std::stoll(content_length_str);
923+
} catch (const std::exception& e) {
924+
return Status::InvalidArgument("invalid HTTP header CONTENT_LENGTH={}: {}",
925+
content_length_str, e.what());
926+
}
927+
}
921928
if (content_length < 0) {
922929
std::stringstream ss;
923930
ss << "This stream load content length <0 (" << content_length

0 commit comments

Comments
 (0)