Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
/cortex.cppPublic archive

Commit948396b

Browse files
fix: crash if invalid url is set (#2142)
* fix: crash if invalid url is set* fix: validation for hf---------Co-authored-by: sangjanai <sang@jan.ai>
1 parentccf5c91 commit948396b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

‎engine/services/model_service.cc‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,20 @@ cpp::result<DownloadTask, std::string> ModelService::HandleDownloadUrlAsync(
226226
const std::string& url, std::optional<std::string> temp_model_id,
227227
std::optional<std::string> temp_name) {
228228
auto url_obj =url_parser::FromUrlString(url);
229-
if (url_obj.has_error()) {
230-
returncpp::fail("Invalid url:" + url);
229+
if (url_obj.has_error() || url_obj->pathParams.size() <5) {
230+
returncpp::fail(
231+
"Invalid url:" + url +
232+
", a valid URL example is:"
233+
"https://huggingface.co/cortexso/tinyllama/blob/1b/model.gguf");
231234
}
232235

233236
if (url_obj->host ==kHuggingFaceHost) {
234237
if (url_obj->pathParams[2] =="blob") {
235238
url_obj->pathParams[2] ="resolve";
236239
}
240+
}else {
241+
returncpp::fail("Only support pull model from" +
242+
std::string(kHuggingFaceHost));
237243
}
238244
auto author{url_obj->pathParams[0]};
239245
auto model_id{url_obj->pathParams[1]};
@@ -243,10 +249,6 @@ cpp::result<DownloadTask, std::string> ModelService::HandleDownloadUrlAsync(
243249
returnDownloadModelFromCortexsoAsync(model_id, url_obj->pathParams[3]);
244250
}
245251

246-
if (url_obj->pathParams.size() <5) {
247-
returncpp::fail("Invalid url:" + url);
248-
}
249-
250252
std::string huggingFaceHost{kHuggingFaceHost};
251253
std::string unique_model_id ="";
252254
if (temp_model_id.has_value()) {
@@ -798,13 +800,19 @@ cpp::result<ModelPullInfo, std::string> ModelService::GetModelPullInfo(
798800

799801
if (string_utils::StartsWith(input,"https://")) {
800802
auto url_obj =url_parser::FromUrlString(input);
801-
if (url_obj.has_error()) {
802-
returncpp::fail("Invalid url:" + input);
803+
if (url_obj.has_error() || url_obj->pathParams.size() <5) {
804+
returncpp::fail(
805+
"Invalid url:" + input +
806+
", a valid URL example is:"
807+
"https://huggingface.co/cortexso/tinyllama/blob/1b/model.gguf");
803808
}
804809
if (url_obj->host ==kHuggingFaceHost) {
805810
if (url_obj->pathParams[2] =="blob") {
806811
url_obj->pathParams[2] ="resolve";
807812
}
813+
}else {
814+
returncpp::fail("Only support pull model from" +
815+
std::string(kHuggingFaceHost));
808816
}
809817

810818
auto author{url_obj->pathParams[0]};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp