Skip to content

Commit

Permalink
fix(core): fix parse uri crash
Browse files Browse the repository at this point in the history
  • Loading branch information
churchill-zhang authored and zoomchan-cxj committed Feb 9, 2022
1 parent a3f3b8d commit 48f5af3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
5 changes: 4 additions & 1 deletion android/sdk/src/main/jni/src/bridge/java2js.cc
Expand Up @@ -76,9 +76,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>();
Expand Down
9 changes: 9 additions & 0 deletions android/sdk/src/main/jni/src/jni/uri.cc
Expand Up @@ -103,6 +103,9 @@ unicode_string_view Uri::Normalize() {
(jstring)j_env->CallObjectMethod(j_obj_uri_, j_normalize_method_id);
auto 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);
Expand All @@ -114,6 +117,9 @@ unicode_string_view Uri::GetScheme() {
JNIEnv* j_env = JNIEnvironment::GetInstance()->AttachCurrentThread();
auto 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;
Expand All @@ -124,6 +130,9 @@ unicode_string_view Uri::GetPath() {
JNIEnv* j_env = JNIEnvironment::GetInstance()->AttachCurrentThread();
auto 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;
Expand Down
24 changes: 21 additions & 3 deletions android/sdk/src/main/jni/src/loader/adr_loader.cc
Expand Up @@ -52,7 +52,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") {
Expand All @@ -79,10 +89,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") {
Expand All @@ -104,10 +122,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;
}
}

Expand Down

0 comments on commit 48f5af3

Please sign in to comment.