From 11189a02b96a1c6bb878feb2fe25a75533b9fc32 Mon Sep 17 00:00:00 2001 From: yang-jingbo1985 Date: Mon, 1 Apr 2024 22:39:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=AE=80=E6=8A=A5=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=E7=BC=96=E7=A0=81=20Signed-off-by:?= =?UTF-8?q?=20yangjingbo10=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iaa13a7f28d724371546f926e10bf67c9cbcf7e42 --- frameworks/native/backup_ext/BUILD.gn | 1 + .../native/backup_ext/src/ext_extension.cpp | 17 ++++++++++---- test/fuzztest/backupext_fuzzer/BUILD.gn | 1 + tests/unittests/backup_ext/BUILD.gn | 2 ++ tests/unittests/backup_utils/BUILD.gn | 1 + utils/BUILD.gn | 1 + utils/include/b_json/b_report_entity.h | 10 +++++++++ utils/src/b_json/b_report_entity.cpp | 22 ++++++++++++++++++- 8 files changed, 50 insertions(+), 5 deletions(-) diff --git a/frameworks/native/backup_ext/BUILD.gn b/frameworks/native/backup_ext/BUILD.gn index eb044ee94..ee46ddb11 100644 --- a/frameworks/native/backup_ext/BUILD.gn +++ b/frameworks/native/backup_ext/BUILD.gn @@ -50,6 +50,7 @@ ohos_shared_library("backup_extension_ability_native") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/interfaces/innerkits/native:sandbox_helper_native", "${path_backup}/utils:backup_utils", "${path_jsoncpp}:jsoncpp", ] diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index f3cc2c8bd..3fc043037 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -50,6 +50,7 @@ #include "b_tarball/b_tarball_factory.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" +#include "sandbox_helper.h" #include "service_proxy.h" #include "tar_file.h" #include "untar_file.h" @@ -799,10 +800,16 @@ static void RestoreBigFiles(bool appendTargetPath) continue; } - string fileName = path + item.hashName; - string filePath = appendTargetPath ? (path + item.fileName) : item.fileName; + string itemHashName = item.hashName; + string itemFileName = item.fileName; - if (!RestoreBigFilePrecheck(fileName, path, item.hashName, filePath)) { + BReportEntity::DecodeReportItem(item.hashName, itemHashName, true); + BReportEntity::DecodeReportItem(item.fileName, itemFileName, true); + + string fileName = path + itemHashName; + string filePath = appendTargetPath ? (path + itemFileName) : itemFileName; + + if (!RestoreBigFilePrecheck(fileName, path, itemHashName, filePath)) { continue; } @@ -1340,7 +1347,9 @@ static void WriteFile(const string &filename, const map GetReportInfos(); + /** + * @brief encode report item + */ + static void EncodeReportItem(const std::string &reportItem, std::string& encodeItem, bool enableEncode); + + /** + * @brief decode report item + */ + static void DecodeReportItem(const std::string &reportItem, std::string& decodeItem, bool enableEncode); + public: /** * @brief 构造方法 diff --git a/utils/src/b_json/b_report_entity.cpp b/utils/src/b_json/b_report_entity.cpp index 02fbb3c68..1551cff25 100644 --- a/utils/src/b_json/b_report_entity.cpp +++ b/utils/src/b_json/b_report_entity.cpp @@ -23,6 +23,7 @@ #include "b_error/b_error.h" #include "filemgmt_libhilog.h" +#include "sandbox_helper.h" #include "unique_fd.h" namespace OHOS::FileManagement::Backup { @@ -80,7 +81,7 @@ static ErrCode ParseReportInfo(struct ReportFileInfo &fileStat, return EPERM; } path = (path.length() > 0 && path[0] == '/') ? path.substr(1, path.length() - 1) : path; - fileStat.filePath = path.substr(0, path.length() - 1); + BReportEntity::DecodeReportItem(path.substr(0, path.length() - 1), fileStat.filePath, true); if (keys.find(INFO_MODE) != keys.end()) { fileStat.mode = residue[keys.find(INFO_MODE)->second]; } @@ -169,4 +170,23 @@ unordered_map BReportEntity::GetReportInfos() return infos; } + +void BReportEntity::EncodeReportItem(const string &reportItem, string& encodeItem, bool enableEncode) +{ + if (enableEncode) { + encodeItem = AppFileService::SandboxHelper::Encode(reportItem); + } else { + encodeItem = reportItem; + } +} + +void BReportEntity::DecodeReportItem(const string &reportItem, string& decodeItem, bool enableEncode) +{ + if (enableEncode) { + decodeItem = AppFileService::SandboxHelper::Decode(reportItem); + } else { + decodeItem = reportItem; + } +} + } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee