已关闭
物理路径转沙箱路径优化适配 #20367
dgm_2399562创建于 3 天前关闭于 2 天前
物理路径转沙箱路径优化适配 #20367
已关闭
dgm_2399562创建于 3 天前关闭于 2 天前
已删除 :master合入到openharmony/ability_ability_runtimemaster
dgm_2399562
dgm_2399562
3 天前

物理路径转沙箱路径优化适配

likedislike
当前Pull Request已关闭, 关闭人@dgm_2399562
afwk_helper成员
3 天前 评论:

开始进行AI检视!

AI review has been started, please wait...

likedislike
afwk_helper成员
3 天前 评论:
check type result report
start ai_review pass -
likedislike
openharmony_ciopenharmony_ci成员
3 天前 添加了label:waiting_on_author
openharmony_ci
openharmony_ci成员
3 天前 评论:

感谢提交 Pull Requests !此PR未通过DCO校验。
校验失败可能原因:

1. 未签署“DCO协议”(开发者原创声明协议),在线签署、查看签署状态

2. Commits 中未包含 Signed-off-by信息,参考FAQ处理

修复上述问题后,在PR的评论框输入“check dco” ,单击”评论”,系统将再次进行DCO校验。

当前检测到如下Commits 未包含Signed-off-by信息:


Thanks for submitting a pull request. This pull request has not passed the DCO check.
Possible causes:

1. You have not signed the Developer Certificate of Origin (DCO). Sign the DCO and check DCO status.

2. The commits do not contain the Signed-off-by information. To resolve this issue, see FAQs.

After resolving the preceding issues, enter check dco in the comment box of this pull request and click Comment. The system will check DCO status again.

The following commits do not contain the Signed-off-by information:

likedislike
openharmony_ciopenharmony_ci成员
3 天前 添加了label:dco检查失败
afwk_helper成员
3 天前 评论:

🚨 🤖 AI 代码检视报告 🚨

总体评估: CRITICAL

问题统计:

  • 总问题数: 4
  • 严重问题: 1
  • 高危问题: 2

摘要:
本PR将多处基于 std::regex 的物理路径转沙箱路径逻辑统一替换为 ExtractorUtil::GetLoadFilePath 等公共方法,方向正确,但 js_module_reader.cpp 误删了 bundleMgrProxy 空指针检查、新增的 GetStoragePath 实现存在空指针/npos 风险且行为与原逻辑不一致,需优先修复。

📊 详细报告
查看完整的审查详情,包括具体的问题描述、建议和代码位置:
🔗 查看详细报告


此评论由 OpenHarmony Insight 代码审查系统自动生成

likedislike
afwk_helper成员3 天前进行代码检视1
frameworks/native/runtime/js_module_reader.cpp
@@ -291,4 +287,2 @@
291- return;
292- }
293287 AppExecFwk::BundleInfo bundleInfo;
294288 auto getInfoResult = bundleMgrProxy->GetBundleInfoForSelf(static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::
afwk_helper3 天前评论:

🤖 AI 代码检视意见(回复本评论可解决检视意见,点击被检视代码行左侧的小头像可收起检视意见)


🔴 删除 bundleMgrProxy 空指针检查导致潜在 NPE

位置: L288-L290 | 严重程度: Critical

❓ 问题描述

原代码在 iface_cast 之后立即检查 bundleMgrProxy 是否为空并 return;本次 PR 删除了该检查。若 remoteObject 无效或服务未就绪,bundleMgrProxy 将为 nullptr,随后调用 bundleMgrProxy->GetBundleInfoForSelf(...) 会直接解引用空指针导致进程崩溃。这正是 OpenHarmony 平台强调的 IPC 反序列化/代理空检查要求所禁止的。

💡 修复建议

修改建议:在 iface_cast 之后保留对 bundleMgrProxy 的空指针检查,避免对 nullptr 调用方法。

288: auto bundleMgrProxy = iface_cast(remoteObject);
289: if (bundleMgrProxy == nullptr) {
290: TAG_LOGE(AAFwkTag::JSRUNTIME, "null bundleMgrProxy");
291: return;
292: }
293: AppExecFwk::BundleInfo bundleInfo;


likedislike
afwk_helper成员3 天前进行代码检视1
services/appmgr/src/app_mgr_service_inner.cpp
@@ -2262,8 +2262,8 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr<AbilityInfo> abilityInfo, s
22622262 appInfo->bundleName = hostBundleName;
22632263 std::regex pattern(
22642264 std::string(ABS_CODE_PATH) + std::string(FILE_SEPARATOR) + hostBundleName);
2265- abilityInfo->hapPath = std::regex_replace(abilityInfo->hapPath, pattern, LOCAL_CODE_PATH);
2266- abilityInfo->resourcePath = std::regex_replace(abilityInfo->resourcePath, pattern, LOCAL_CODE_PATH);
2265+ abilityInfo->hapPath = GetStoragePath(abilityInfo->hapPath);
2266+ abilityInfo->resourcePath = GetStoragePath(abilityInfo->resourcePath);
22672267 GetBundleAndHapInfo(*abilityInfo, appInfo, bundleInfo, hapModuleInfo, appIndex);
22682268 appInfo = std::make_shared<ApplicationInfo>(bundleInfo.applicationInfo);
22692269 auto pluginRet = DelayedSingleton<BundleMgrHelper>::GetInstance()->GetPluginHapModuleInfo(
@@ -13409,6 +13409,13 @@ void AppMgrServiceInner::CheckRenderAttachTimeout(std::shared_ptr<RenderRecord>
1340913409 ProcessStartFailedReason::ATTACH_TIMEOUT, elapsedMs);
1341013410}
1341113411 
13412+std::string AppMgrServiceInner::GetStoragePath(const std::string& hapPath) {
afwk_helper3 天前评论:

🤖 AI 代码检视意见(回复本评论可解决检视意见,点击被检视代码行左侧的小头像可收起检视意见)


🟠 GetStoragePath 未校验 find 返回 npos 且语义与原 regex 转换不一致

位置: L13412-L13417 | 严重程度: High

❓ 问题描述

新函数 GetStoragePath 用 std::regex_replace 去掉 ABS_CODE_PATH+FILE_SEPARATOR,再调用 loadPath.find(FILE_SEPARATOR)+1 取子串。若 find 返回 std::string::npos,则 npos+1 在无符号运算下回绕为 0,substr(0) 返回整串,行为不直观且非预期;此外原调用点使用的是 ABS_CODE_PATH + FILE_SEPARATOR + hostBundleName 的精确 pattern,新实现完全忽略了 hostBundleName 维度,对非匹配 hostBundleName 的路径会产生错误结果。代码风格上还混用了 Tab 与空格缩进。

💡 修复建议

修改建议:显式判空与检查 npos,并保持与原 regex 转换的语义一致;统一使用 4 空格缩进,避免 Tab 混入。

13412: std::string AppMgrServiceInner::GetStoragePath(const std::string& hapPath) {
13413: if (hapPath.empty()) {
13414: return hapPath;
13415: }
13416: std::regex hapPattern(std::string(ABS_CODE_PATH) + std::string(FILE_SEPARATOR));
13417: std::string loadPath = std::regex_replace(hapPath, hapPattern, "");
13418: auto pos = loadPath.find(std::string(FILE_SEPARATOR));
13419: if (pos == std::string::npos) {
13420: return std::string(LOCAL_CODE_PATH) + std::string(FILE_SEPARATOR) + loadPath;
13421: }
13422: loadPath = std::string(LOCAL_CODE_PATH) + std::string(FILE_SEPARATOR) + loadPath.substr(pos + 1);
13423: return loadPath;
13424: }


likedislike
afwk_helper成员3 天前进行代码检视1
ets_environment/frameworks/ets_environment/src/ets_environment.cpp
@@ -1002,3 +1000,2 @@
10021000 std::string targetPath = pluginHspPath;
1003- std::regex patter(std::string(ABS_DATA_CODE_PATH) + bundleName_ + "/");
1004- targetPath = std::regex_replace(targetPath, patter, std::string(ABS_CODE_PATH) + std::string(BUNDLE));
1001+ std::regex patter(AbilityRuntime::Runtime::GetSendboxPath());
afwk_helper3 天前评论:

🤖 AI 代码检视意见(回复本评论可解决检视意见,点击被检视代码行左侧的小头像可收起检视意见)


🟠 substr(find('/')+1) 未处理 npos 且引用疑似拼写错误的 GetSendboxPath

位置: L1001-L1003 | 严重程度: High

❓ 问题描述

新代码使用 targetPath.find("/")+1 取子串,若 find 返回 npos,则 npos+1 回绕为 0,结果为整串,行为不明确;同时 AbilityRuntime::Runtime::GetSendboxPath() 看起来是 Sandbox 的拼写错误,若 API 命名确为如此则可忽略,否则编译会失败或调用错误方法。此外变量名 patter 仍保留拼写错误(应为 pattern),代码风格上还使用了 Tab 缩进与项目其他位置不一致。

💡 修复建议

修改建议:显式判断 find 结果是否为 npos;确认并使用正确的 Sandbox API 名称;将变量名 patter 改为 pattern,并将 Tab 替换为 4 空格缩进。

1001: std::regex pattern(AbilityRuntime::Runtime::GetSandboxPath());
1002: targetPath = std::regex_replace(targetPath, pattern, "");
1003: auto pos = targetPath.find("/");
1004: targetPath = (pos == std::string::npos) ? (std::string(BUNDLE_INSTALL_PATH) + targetPath)
1005: : (std::string(BUNDLE_INSTALL_PATH) + targetPath.substr(pos + 1));


likedislike
dgm_2399562
dgm_2399562
3 天前 评论:

check dco

likedislike
openharmony_ci
openharmony_ci成员
3 天前 评论:

感谢提交 Pull Requests !此PR未通过DCO校验。
校验失败可能原因:

1. 未签署“DCO协议”(开发者原创声明协议),在线签署、查看签署状态

2. Commits 中未包含 Signed-off-by信息,参考FAQ处理

修复上述问题后,在PR的评论框输入“check dco” ,单击”评论”,系统将再次进行DCO校验。

当前检测到如下Commits 未包含Signed-off-by信息:


Thanks for submitting a pull request. This pull request has not passed the DCO check.
Possible causes:

1. You have not signed the Developer Certificate of Origin (DCO). Sign the DCO and check DCO status.

2. The commits do not contain the Signed-off-by information. To resolve this issue, see FAQs.

After resolving the preceding issues, enter check dco in the comment box of this pull request and click Comment. The system will check DCO status again.

The following commits do not contain the Signed-off-by information:

likedislike
dgm_2399562dgm_2399562
2 天前 关闭了 pull request