fix(core): fix parse uri crash

This commit is contained in:
pollyzhang
2021-08-09 14:46:43 +08:00
committed by churchill-zhang
parent 6bf31c765a
commit 1ecd92e857
4 changed files with 53 additions and 11 deletions
+19 -7
View File
@@ -133,6 +133,7 @@ bool RunScript(std::shared_ptr<Runtime> runtime,
<< ", uri = " << uri
<< ", asset_manager = " << asset_manager;
unicode_string_view script_content;
bool read_script_flag;
unicode_string_view code_cache_content;
uint64_t modify_time = 0;
@@ -180,20 +181,28 @@ bool RunScript(std::shared_ptr<Runtime> runtime,
task_runner = engine->GetWorkerTaskRunner();
task_runner->PostTask(std::move(task));
u8string content;
runtime->GetScope()->GetUriLoader()->RequestUntrustedContent(uri, content);
script_content = unicode_string_view(std::move(content));
read_script_flag = runtime->GetScope()->GetUriLoader()
->RequestUntrustedContent(uri, content);
if (read_script_flag) {
script_content = unicode_string_view(std::move(content));
}
code_cache_content = read_file_future.get();
} else {
u8string content;
runtime->GetScope()->GetUriLoader()->RequestUntrustedContent(uri, content);
script_content = unicode_string_view(std::move(content));
read_script_flag = runtime->GetScope()->GetUriLoader()
->RequestUntrustedContent(uri, content);
if (read_script_flag) {
script_content = unicode_string_view(std::move(content));
}
}
TDF_BASE_DLOG(INFO) << "uri = " << uri
<< "read_script_flag = " << read_script_flag
<< ", script content = " << script_content;
if (StringViewUtils::IsEmpty(script_content)) {
TDF_BASE_LOG(WARNING) << "script content empty, uri = " << uri;
if (!read_script_flag || StringViewUtils::IsEmpty(script_content)) {
TDF_BASE_LOG(WARNING) << "read_script_flag = " << read_script_flag
<< ", script content empty, uri = " << uri;
return false;
}
@@ -260,7 +269,10 @@ jboolean RunScriptFromUri(JNIEnv* j_env,
std::chrono::system_clock::now())
.time_since_epoch()
.count();
if (!j_uri) {
TDF_BASE_DLOG(WARNING) << "HippyBridgeImpl runScriptFromUri, j_uri invalid";
return false;
}
const unicode_string_view uri = JniUtils::ToStrView(j_env, j_uri);
const unicode_string_view code_cache_dir =
JniUtils::ToStrView(j_env, j_code_cache_dir);
@@ -74,9 +74,12 @@ void CallFunction(JNIEnv* j_env,
TDF_BASE_DLOG(WARNING) << "CallFunction j_runtime_id invalid";
return;
}
std::shared_ptr<JavaScriptTaskRunner> runner =
runtime->GetEngine()->GetJSRunner();
if (!j_action) {
TDF_BASE_DLOG(WARNING) << "CallFunction j_action invalid";
return;
}
unicode_string_view action_name = JniUtils::ToStrView(j_env, j_action);
std::shared_ptr<JavaRef> cb = std::make_shared<JavaRef>(j_env, j_callback);
std::shared_ptr<JavaScriptTask> task = std::make_shared<JavaScriptTask>();
+9
View File
@@ -103,6 +103,9 @@ unicode_string_view Uri::Normalize() {
(jstring)j_env->CallObjectMethod(j_obj_uri_, j_normalize_method_id);
jstring j_parsed_uri =
(jstring)j_env->CallObjectMethod(j_normalize_uri, j_to_string_method_id);
if (!j_parsed_uri) {
return u"";
}
unicode_string_view ret = JniUtils::ToStrView(j_env, j_parsed_uri);
j_env->DeleteLocalRef(j_parsed_uri);
j_env->DeleteLocalRef(j_normalize_uri);
@@ -114,6 +117,9 @@ unicode_string_view Uri::GetScheme() {
JNIEnv* j_env = JNIEnvironment::GetInstance()->AttachCurrentThread();
jstring j_scheme =
(jstring)j_env->CallObjectMethod(j_obj_uri_, j_get_scheme_method_id);
if (!j_scheme) {
return u"";
}
unicode_string_view ret = JniUtils::ToStrView(j_env, j_scheme);
j_env->DeleteLocalRef(j_scheme);
return ret;
@@ -124,6 +130,9 @@ unicode_string_view Uri::GetPath() {
JNIEnv* j_env = JNIEnvironment::GetInstance()->AttachCurrentThread();
jstring j_path =
(jstring)j_env->CallObjectMethod(j_obj_uri_, j_get_path_method_id);
if (!j_path) {
return u"";
}
unicode_string_view ret = JniUtils::ToStrView(j_env, j_path);
j_env->DeleteLocalRef(j_path);
return ret;
@@ -51,7 +51,17 @@ bool ADRLoader::RequestUntrustedContent(const unicode_string_view& uri,
return false;
}
unicode_string_view schema = uri_obj->GetScheme();
if (StringViewUtils::IsEmpty(schema)) {
TDF_BASE_DLOG(ERROR) << "schema error, uri = " << uri;
cb(u8string());
return false;
}
unicode_string_view path = uri_obj->GetPath();
if (StringViewUtils::IsEmpty(path)) {
TDF_BASE_DLOG(ERROR) << "path error, uri = " << uri;
cb(u8string());
return false;
}
TDF_BASE_DCHECK(schema.encoding() == unicode_string_view::Encoding::Utf16);
std::u16string schema_str = schema.utf16_value();
if (schema_str == u"file") {
@@ -78,10 +88,18 @@ bool ADRLoader::RequestUntrustedContent(const unicode_string_view& uri,
std::shared_ptr<Uri> uri_obj = Uri::Create(uri);
if (!uri_obj) {
TDF_BASE_DLOG(ERROR) << "uri error, uri = " << uri;
return "";
return false;
}
unicode_string_view schema = uri_obj->GetScheme();
if (StringViewUtils::IsEmpty(schema)) {
TDF_BASE_DLOG(ERROR) << "schema error, uri = " << uri;
return false;
}
unicode_string_view path = uri_obj->GetPath();
if (StringViewUtils::IsEmpty(path)) {
TDF_BASE_DLOG(ERROR) << "path error, uri = " << uri;
return false;
}
TDF_BASE_DCHECK(schema.encoding() == unicode_string_view::Encoding::Utf16);
std::u16string schema_str = schema.utf16_value();
if (schema_str == u"file") {
@@ -103,10 +121,10 @@ bool ADRLoader::RequestUntrustedContent(const unicode_string_view& uri,
}
TDF_BASE_DLOG(ERROR) << "aasset_manager error, uri = " << uri;
return "";
return false;
} else {
TDF_BASE_DLOG(ERROR) << "schema error, schema = " << schema;
return "";
return false;
}
}