From 525c5b762a3968b49cf53615cfbcd0bd41cdba69 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Mon, 28 Jul 2025 10:17:37 +0000 Subject: [PATCH 01/12] =?UTF-8?q?photo=5Fedit=5Fsize=5Foperation.cpp?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E7=8E=87=E4=B8=8D=E8=BE=BE=E6=A0=87=EF=BC=8C?= =?UTF-8?q?gap90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- .../innerkitsimpl/test/fuzztest/BUILD.gn | 1 + .../BUILD.gn | 69 ++++ .../corpus/init | 16 + ...brary_photo_edit_size_operation_fuzzer.cpp | 304 ++++++++++++++++++ ...library_photo_edit_size_operation_fuzzer.h | 21 ++ .../project.xml | 25 ++ 6 files changed, 436 insertions(+) create mode 100644 frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn create mode 100644 frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/corpus/init create mode 100644 frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp create mode 100644 frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.h create mode 100644 frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/project.xml diff --git a/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn index 11003a698d..f67a7f1bd7 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn @@ -16,6 +16,7 @@ import("//foundation/multimedia/media_library/media_library.gni") group("media_library_fuzztest") { testonly = true deps = [ + "medialibraryphotoeditsizeoperation_fuzzer:MediaLibraryPhotoEditSizeOperationFuzzTest" "media_bgtask_aging_task_fuzzer:MediaBgtaskAgingTaskFuzzTest", "mediabgtaskmgrappbgtaskschedulestub_fuzzer:MediaBgtaskMgrAppBgtaskScheduleStubFuzzTest", "mediabgtaskmgrappopsconnectability_fuzzer:MediaBgtaskMgrAppOpsConnectAbilityFuzzTest", diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn new file mode 100644 index 0000000000..4f2abcb635 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/multimedia/media_library/media_library.gni") + +ohos_fuzztest("MediaLibraryPhotoEditSizeOperationFuzzTest") { + module_out_path = "media_library/media_library" + fuzz_config_file = "." + + include_dirs = [ + ".", + "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include", + "${MEDIALIB_INNERKITS_PATH}/inner_api/media_library_helper/include", + ] + + sources = [ + "./media_library_photo_edit_size_operation_fuzzer.cpp", + ] + + deps = [ + "${MEDIALIB_INNERKITS_PATH}/media_library_helper:media_library", + "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension:medialibrary_data_extension", + ] + + external_deps = [ + "hitrace:hitrace_meter", + "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "access_token:libnativetoken_shared", + "access_token:libtokensetproc_shared", + "ability_base:zuri", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "ability_runtime:app_context", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "data_share:datashare_common", + "data_share:datashare_provider", + "device_manager:devicemanagersdk", + "dfs_service:cloudsync_kit_inner", + "hilog:libhilog", + "ipc:ipc_single", + "kv_store:distributeddata_inner", + "napi:ace_napi", + "player_framework:media_client", + "relational_store:native_rdb", + "relational_store:rdb_data_share_adapter", + "ability_runtime:dataobs_manager", + "app_file_service:fileuri_native", + "data_share:datashare_consumer", + "e2fsprogs:libext2_uuid", + "image_framework:image_native", + "user_file_service:file_access_extension_ability_kit", + "ipc:ipc_napi", + ] +} \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/corpus/init b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/corpus/init new file mode 100644 index 0000000000..7fdbabd923 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp new file mode 100644 index 0000000000..3cb88b9c03 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp @@ -0,0 +1,304 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "media_library_photo_edit_size_operation_fuzzer.h" + +#include +#include +#include +#include + +#include "photo_edit_size_operation.h" +#include "ability_context_impl.h" +#include "media_log.h" +#include "rdb_utils.h" +#include "medialibrary_rdbstore.h" +#include "medialibrary_data_manager.h" +#include "medialibrary_unistore_manager.h" +#include "medialibrary_kvstore_manager.h" +#include "medialibrary_photo_operation.h" +#include "media_file_utils.h" +#include "result_set_utils.h" + +namespace OHOS { +namespace Media { +using namespace std; +using namespace OHOS::NativeRdb; +using namespace OHO::DataShare; +using OHOS::DataSharePredicates; + +struct PhotoMode { + string path; + int64_t editTime; +}; + +struct TakePhotoResult { + int32_t fileId; + string path; +}; + +static const int32_t NUM_BYTES = 1; +static const std::string EDITDATA_VALUE = "{\"imageEffect\":{\"filters\":[{\"name\":\"InplaceSticker\"," + "\"values\":{\"RESOURCE_DIRECTORY\":\"/sys_prod/resource/camera\"}}],\"name\":\"brandWaterMark\"}}"; +static const std::string COMPATIBLE_FORMAT_VALUE = "com.demo.test"; +static const std::string FORMAT_VERSION_VALUE = "0"; +static const std::string CAMERA_BUNDLE_NAME = "com.huawei.hmos.camera"; + +FuzzedDataProvider *provider = nullptr; +std::shared_ptr grdbStore; + +static const unit8_t BUF[] = { + 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 96, 0, 96, 0, 0, 255, 219, 0, 67, 0, 8, 6, 6, 7, 6, 5, 8, + 7, 7, 7, 9, 9, 8, 10, 12, 20, 13, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26, 31, 30, 29, 26, 28, 28, 32, 36, 46, + 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 57, 61, 56, 50, 60, 46, 51, 52, 50, 255, + 219, 0, 67, 1, 9, 9, 9, 12, 11, 12, 24, 13, 13, 24, 50, 33, 28, 33, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, +}; + +string fileName = ""; +TakePhotoResult result = { }; +string fileIdString = ""; +string filePath = ""; +vector fileIds = { }; +vector filePaths = { }; + +int32_t WriteFile(int destfd) +{ + write(destfd, BUF, sizeof(BUF)); + retiurn E_OK; +} + +string CreateCacheFile() +{ + string cacheFileName = fileName; + string uri = PhotoColumn::PHOTO_CACH_URI_PREFIX + cacheFileName; + MediaFileUtils::UriAppendKeyValue(uri, URI_PARAM_API_VERSION, to_string(MEDIA_API_VERSION_V10)) + Uri openCacheUri(uri); + MediaLibraryCommand cmd(openCacheUri); + int32_t cacheFileFd = MediaLibraryDataManager::GetInstance()->OpenFile(cmd, "w"); + WriteFile(cacheFileFd); + close(cacheFileFd); + return cacheFileName; +} + +int32_t CreatePhotoAsset() +{ + MediaLibraryCommand cmd(OperationObject::FILESYSTEM_PHOTO, OperationType::CREATE, + MediaLibraryApi::API_10); + OHOS::NativeRdb::ValuesBucket values; + string displayName = fileName; + return ret; +} + +void SubmitCache(DataShareValuesBucket &valuesBucket, bool isAddWater, bool isEdited) +{ + MediaLibraryCommand submitCacheCmd(OperationObject::FILESYSTEM_PHOTO, + OperationType::SUBMIT_CACHE, MediaLibraryApi::API_10); + if (isAddWater && !isEdited) { + // 预留 + } + string assetUri; + MediaLibraryDataManger::GetInstance()->InsertExt(submitCacheCmd, valuesBucket, assetUri); +} + +DataShareValuesBucket GetValuesBucket(int32_t fileId, std::string cacheFileName, bool isSetEditData) +{ + DataShareValuesBucket valuesBucket; + valuesBucket.Put(PhootoColumn::MEDIA_ID, fileId); + valuesBucket.Put(CACHE_FILE_NAME, cacheFileName); + if(isSetEditData) { + valuesBucket.Put(EDIT_DATA, EDITDATA_VALUE); + valuesBucket.Put(COMPATIBLE_FORMAT, COMPATIBLE_FORMAT_VALUE); + valuesBucket.Put(FORMAT_VERSION, FORMAT_VERSION_VALUE); + } + return valuesBucket; +} + +PhotoMode GetPhotoMode(int fileId) +{ + PhotoMode photoMode; + vector colums = { PhotoColumn::MEDIA_FILE_PATH, PhotoColum::PHOTO_EDIT_TIME }; + MediaLibraryCommand cmd(OperationObject::FILESYSTEM_PHOTO, OperationType::QUERY, + MediaLibraryApi::API_10); + cmd.GetAbsRdbPredicates()->EqualTo(PhotoColum::MEDIA_ID, to_string(fileId)); + auto resultSet = g_rdbStore->Query(cmd, columns); + resultSet->GoToFirstRow(); + photoMode.path = GetStringVal(PhotoColumn::MEDIA_FILE_PATH, resultSet); + photoMode.editTime = GetInt64Val(PhotoColumn::PHOTO_EDIT_TIME, resultSet); + return photoMode; +} + +string GetFilePath(int fileId) +{ + PhotoMode mode = GetPhotoMode(fileId); + return mode.path; +} + +TakePhotoResult TakePhotoMock(bool isAddWater) +{ + TakePhotoResult result; + string cacheFileName = CreateCacheFile(); + int32_t fileId = CreatePhotoAsset(); + string path = GetFilePath(fileId); + result.fileId = fileId; + result.path = path; + DataShareValuesBucket valuesBucket; + valuesBucket.Put(PhotoColum::MEDIA_ID, fileId); + valuesBucket.Put(CACHE_FILE_NAME, cacheFileName); + if (!isAddWater) { + SubmitCache(valuesBucket, isAddWater, false); + } else { + valuesBucket.Put(EDIT_DATA, EDITDATA_VALUE); + valuesBucket.Put(COMPATIBLE_FORMAT, COMPATIBLE_FORMAT_VALUE); + valuesBucket.Put(FORMAT_VERSION, FORMAT_VERSION_VALUE); + SubmitCache(valuesBucket, isAddWater, false); + } + return result; +} + +void EditPhoto(TakePhotoResult result, bool isSetEditData, bool isAddWater) +{ + string cacheFileName = CreateCacheFile(); + DataShareValuesBucket valuesBucket = GetValuesBucket(result.fileId, cacheFileName, isSetEditData); + submitCache(valuesBucket, isAddWater, true); +} + +bool isEdited(int fileId) +{ + PhotoMode mode = GetPhotoMode(fileId); + return mode.editTime > 0; +} + +void WriteDefferedPhoto(bool &isEdited, std::string &path) +{ + MediaLibraryPhotoOperations::ProcessMultistagesPhoto(isEdited, path, BUF, sizeof(BUF), 1); +} + +static void RandomDataInit() +{ + fileName = provider->ConsumeBytesAsString(NUM_BYTES) + ".jpg"; + + result = TakePhotoMock(true); + EditPhoto(result, true, true); + bool isEdited = IsEdited(result.fileId); + WriteDefferedPhoto(isEdited, result.path); + + fileIdStr = std::to_string(result.fileId); + filePath = result.path; + + fileIds.push_back(fileIdStr); + filePaths.push_back(filePath); +} + +static void PhotoEditSizeOperationTest() +{ + bool hasMore = provider->ConsumeBool(); + int limitCount = provider->ConsumeIntegral(); + std::string startFileId = ""; + + PhotoEditSizeOperation::CalSingleEditDataSize(fileIdStr.c_str(), filePath); + PhotoEditSizeOperation::GetFileIdByCloudPath(g_rdbStore, fileIdStr, filePath); + PhotoEditSizeOperation::GetFileIdsAndPathS(g_rdbStore, fileIds, fileIds, filePaths, startFileId, hasMore, limitCount); + PhotoEditSizeOperation::UpdateMediaSizeFromStorage(); +} + +static void SetTables() +{ + vector createTableSqlList = { Media::PhotoColumn::CREATE_PHOTO_TABLE }; + for (auto &createTableSql : createTableSqlList) { + CHECK_AND_RETURN_LOG(g_rdbStore != nullptr, "g_rdbStore is null"); + int32_t ret = g_rdbStore->ExecuteSql(createTableSql); + if (ret != NativeRdb::E_OK) { + MEDIA_ERR_LOG("Execute sql %{private}s failed", createTableSql.c_str()); + return; + } + MEDIA_DEBUG_LOG("Execute Sql %{private}s success", createTableSql,c_str); + } +} + +static void Init() +{ + auto stageContext = std::make_shared(); + auto abilityContextImpl = std::make_shared(); + abilityContestImpl->SetStageContext(stageContext); + int32_t sceneCode = 0; + auto ret = Media::MediaLibraryDataManager::GetInstance()->InitMediaLibraryMgr(abilityContextImpl, + abilityContextImpl, sceneCode); + CHECK_AND_RETURN_LOG(ret == NativeRdb::E_OK, "InitMediaLibrary Mgr failed, ret : %{public}d", ret); + auto rdbStore = Media::MediaLibraryUnistoreManager::GetInstance().GetRdbStore(); + if (rdbStore == nullptr) { + MEDIA_ERR_LOG("rdbStore is nullptr"); + return; + } + g_rdbStore = rdbStore; + SetTables(); +} + +static inline void CleatKvStore() +{ + Media::MediaLibraryKvStoreManager::GetInstance().CloseAllKvStore(); +} + +} // namespace Media +} // namespace OHOS + +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Media::Init(); + return 0; +} + +extern "C"LLVMFuzzerTestOneInput(const unit8_t *data, size_t size) +{ + FuzzedDataProvider fdp(data, size); + OHOS::Media::provider = &fdp; + if (data == nullptr) { + return 0; + } + OHOS::Media::RandomDatainit(); + OHOS::Media::PhotoEditSizeOperationTest(); + OHOS::Media::ClearKvStore(); + return 0; +} diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.h b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.h new file mode 100644 index 0000000000..84e255ad3d --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.h @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2025 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef NOTIFYCHANGE_FUZZER_H +#define NOTIFYCHANGE_FUZZER_H + +#define FUZZ_PROJECT_NAME "media_library_photo_edit_size_operation_fuzzer" + +#endif \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/project.xml b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/project.xml new file mode 100644 index 0000000000..0610e58171 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1500 + + 300 + + 4096 + + -- Gitee From 6a7e04d0a273dfabc4c1ad80d210ad652faba3e0 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Mon, 28 Jul 2025 10:55:15 +0000 Subject: [PATCH 02/12] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- ...brary_photo_edit_size_operation_fuzzer.cpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp index 3cb88b9c03..c955b66081 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp @@ -54,7 +54,7 @@ static const std::string EDITDATA_VALUE = "{\"imageEffect\":{\"filters\":[{\"nam "\"values\":{\"RESOURCE_DIRECTORY\":\"/sys_prod/resource/camera\"}}],\"name\":\"brandWaterMark\"}}"; static const std::string COMPATIBLE_FORMAT_VALUE = "com.demo.test"; static const std::string FORMAT_VERSION_VALUE = "0"; -static const std::string CAMERA_BUNDLE_NAME = "com.huawei.hmos.camera"; +static const std::string CAMERA_BUNDLE_NAME = "com.example.hmos.camera"; FuzzedDataProvider *provider = nullptr; std::shared_ptr grdbStore; @@ -62,7 +62,8 @@ std::shared_ptr grdbStore; static const unit8_t BUF[] = { 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 96, 0, 96, 0, 0, 255, 219, 0, 67, 0, 8, 6, 6, 7, 6, 5, 8, 7, 7, 7, 9, 9, 8, 10, 12, 20, 13, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26, 31, 30, 29, 26, 28, 28, 32, 36, 46, - 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 57, 61, 56, 50, 60, 46, 51, 52, 50, 255, + 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 57, 61, 56, 50, 60, 46, 51, 52, 50, + 255, 219, 0, 67, 1, 9, 9, 9, 12, 11, 12, 24, 13, 13, 24, 50, 33, 28, 33, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, @@ -148,7 +149,7 @@ DataShareValuesBucket GetValuesBucket(int32_t fileId, std::string cacheFileName, DataShareValuesBucket valuesBucket; valuesBucket.Put(PhootoColumn::MEDIA_ID, fileId); valuesBucket.Put(CACHE_FILE_NAME, cacheFileName); - if(isSetEditData) { + if( isSetEditData ) { valuesBucket.Put(EDIT_DATA, EDITDATA_VALUE); valuesBucket.Put(COMPATIBLE_FORMAT, COMPATIBLE_FORMAT_VALUE); valuesBucket.Put(FORMAT_VERSION, FORMAT_VERSION_VALUE); @@ -178,12 +179,12 @@ string GetFilePath(int fileId) TakePhotoResult TakePhotoMock(bool isAddWater) { - TakePhotoResult result; + TakePhotoResult photoResult; string cacheFileName = CreateCacheFile(); int32_t fileId = CreatePhotoAsset(); string path = GetFilePath(fileId); - result.fileId = fileId; - result.path = path; + photoResult.fileId = fileId; + photoResult.path = path; DataShareValuesBucket valuesBucket; valuesBucket.Put(PhotoColum::MEDIA_ID, fileId); valuesBucket.Put(CACHE_FILE_NAME, cacheFileName); @@ -195,17 +196,17 @@ TakePhotoResult TakePhotoMock(bool isAddWater) valuesBucket.Put(FORMAT_VERSION, FORMAT_VERSION_VALUE); SubmitCache(valuesBucket, isAddWater, false); } - return result; + return photoResult; } -void EditPhoto(TakePhotoResult result, bool isSetEditData, bool isAddWater) +void EditPhoto(TakePhotoResult editResult, bool isSetEditData, bool isAddWater) { string cacheFileName = CreateCacheFile(); - DataShareValuesBucket valuesBucket = GetValuesBucket(result.fileId, cacheFileName, isSetEditData); + DataShareValuesBucket valuesBucket = GetValuesBucket(editResult.fileId, cacheFileName, isSetEditData); submitCache(valuesBucket, isAddWater, true); } -bool isEdited(int fileId) +bool IsEdited(int fileId) { PhotoMode mode = GetPhotoMode(fileId); return mode.editTime > 0; @@ -240,7 +241,8 @@ static void PhotoEditSizeOperationTest() PhotoEditSizeOperation::CalSingleEditDataSize(fileIdStr.c_str(), filePath); PhotoEditSizeOperation::GetFileIdByCloudPath(g_rdbStore, fileIdStr, filePath); - PhotoEditSizeOperation::GetFileIdsAndPathS(g_rdbStore, fileIds, fileIds, filePaths, startFileId, hasMore, limitCount); + PhotoEditSizeOperation::GetFileIdsAndPathS(g_rdbStore, fileIds, fileIds, filePaths, + startFileId, hasMore, limitCount); PhotoEditSizeOperation::UpdateMediaSizeFromStorage(); } @@ -254,7 +256,7 @@ static void SetTables() MEDIA_ERR_LOG("Execute sql %{private}s failed", createTableSql.c_str()); return; } - MEDIA_DEBUG_LOG("Execute Sql %{private}s success", createTableSql,c_str); + MEDIA_DEBUG_LOG("Execute Sql %{private}s success", createTableSql.c_str); } } -- Gitee From d21dee49a9986cf77247a11b8e9325e1f6be7ce1 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Mon, 28 Jul 2025 11:17:13 +0000 Subject: [PATCH 03/12] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- ...brary_photo_edit_size_operation_fuzzer.cpp | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp index c955b66081..5a35eac856 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp @@ -62,7 +62,7 @@ std::shared_ptr grdbStore; static const unit8_t BUF[] = { 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 96, 0, 96, 0, 0, 255, 219, 0, 67, 0, 8, 6, 6, 7, 6, 5, 8, 7, 7, 7, 9, 9, 8, 10, 12, 20, 13, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26, 31, 30, 29, 26, 28, 28, 32, 36, 46, - 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 57, 61, 56, 50, 60, 46, 51, 52, 50, + 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 57, 61, 56, 50, 60, 46, 51, 52, 50, 255, 219, 0, 67, 1, 9, 9, 9, 12, 11, 12, 24, 13, 13, 24, 50, 33, 28, 33, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, @@ -98,12 +98,12 @@ static const unit8_t BUF[] = { 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, }; -string fileName = ""; -TakePhotoResult result = { }; -string fileIdString = ""; -string filePath = ""; -vector fileIds = { }; -vector filePaths = { }; +string g_fileName = ""; +TakePhotoResult g_takePhotoResult = { }; +string g_fileIdStr = ""; +string g_filePath = ""; +vector g_fileIds = { }; +vector g_filePaths = { }; int32_t WriteFile(int destfd) { @@ -113,7 +113,7 @@ int32_t WriteFile(int destfd) string CreateCacheFile() { - string cacheFileName = fileName; + string cacheFileName = g_fileName; string uri = PhotoColumn::PHOTO_CACH_URI_PREFIX + cacheFileName; MediaFileUtils::UriAppendKeyValue(uri, URI_PARAM_API_VERSION, to_string(MEDIA_API_VERSION_V10)) Uri openCacheUri(uri); @@ -129,7 +129,7 @@ int32_t CreatePhotoAsset() MediaLibraryCommand cmd(OperationObject::FILESYSTEM_PHOTO, OperationType::CREATE, MediaLibraryApi::API_10); OHOS::NativeRdb::ValuesBucket values; - string displayName = fileName; + string displayName = g_fileName; return ret; } @@ -149,7 +149,7 @@ DataShareValuesBucket GetValuesBucket(int32_t fileId, std::string cacheFileName, DataShareValuesBucket valuesBucket; valuesBucket.Put(PhootoColumn::MEDIA_ID, fileId); valuesBucket.Put(CACHE_FILE_NAME, cacheFileName); - if( isSetEditData ) { + if ( isSetEditData ) { valuesBucket.Put(EDIT_DATA, EDITDATA_VALUE); valuesBucket.Put(COMPATIBLE_FORMAT, COMPATIBLE_FORMAT_VALUE); valuesBucket.Put(FORMAT_VERSION, FORMAT_VERSION_VALUE); @@ -219,18 +219,18 @@ void WriteDefferedPhoto(bool &isEdited, std::string &path) static void RandomDataInit() { - fileName = provider->ConsumeBytesAsString(NUM_BYTES) + ".jpg"; + g_fileName = provider->ConsumeBytesAsString(NUM_BYTES) + ".jpg"; - result = TakePhotoMock(true); - EditPhoto(result, true, true); - bool isEdited = IsEdited(result.fileId); - WriteDefferedPhoto(isEdited, result.path); + g_takePhotoResult = TakePhotoMock(true); + EditPhoto(g_takePhotoResult, true, true); + bool isEdited = IsEdited(g_takePhotoResult.fileId); + WriteDefferedPhoto(isEdited, g_takePhotoResult.path); - fileIdStr = std::to_string(result.fileId); - filePath = result.path; + g_fileIdStr = std::to_string(g_takePhotoResult.fileId); + g_filePath = g_takePhotoResult.path; - fileIds.push_back(fileIdStr); - filePaths.push_back(filePath); + g_fileIds.push_back(g_fileIdStr); + g_filePaths.push_back(g_filePath); } static void PhotoEditSizeOperationTest() @@ -239,9 +239,9 @@ static void PhotoEditSizeOperationTest() int limitCount = provider->ConsumeIntegral(); std::string startFileId = ""; - PhotoEditSizeOperation::CalSingleEditDataSize(fileIdStr.c_str(), filePath); - PhotoEditSizeOperation::GetFileIdByCloudPath(g_rdbStore, fileIdStr, filePath); - PhotoEditSizeOperation::GetFileIdsAndPathS(g_rdbStore, fileIds, fileIds, filePaths, + PhotoEditSizeOperation::CalSingleEditDataSize(g_fileIdStr.c_str(), g_filePath); + PhotoEditSizeOperation::GetFileIdByCloudPath(g_rdbStore, g_fileIdStr, g_filePath); + PhotoEditSizeOperation::GetFileIdsAndPathS(g_rdbStore, g_fileIds, g_fileIds, g_filePaths, startFileId, hasMore, limitCount); PhotoEditSizeOperation::UpdateMediaSizeFromStorage(); } -- Gitee From 38f606db1b5aa64e3ae8d0fdaa1b0b206df341e7 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Mon, 28 Jul 2025 11:28:48 +0000 Subject: [PATCH 04/12] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- .../media_library_photo_edit_size_operation_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp index 5a35eac856..fe67a54039 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp @@ -149,7 +149,7 @@ DataShareValuesBucket GetValuesBucket(int32_t fileId, std::string cacheFileName, DataShareValuesBucket valuesBucket; valuesBucket.Put(PhootoColumn::MEDIA_ID, fileId); valuesBucket.Put(CACHE_FILE_NAME, cacheFileName); - if ( isSetEditData ) { + if (isSetEditData) { valuesBucket.Put(EDIT_DATA, EDITDATA_VALUE); valuesBucket.Put(COMPATIBLE_FORMAT, COMPATIBLE_FORMAT_VALUE); valuesBucket.Put(FORMAT_VERSION, FORMAT_VERSION_VALUE); -- Gitee From 1e479d14a12198905e47852d0b1161605c9177f1 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Mon, 28 Jul 2025 12:12:50 +0000 Subject: [PATCH 05/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- .../innerkitsimpl/test/fuzztest/BUILD.gn | 2 +- .../BUILD.gn | 32 +++++++------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn index f67a7f1bd7..e630a5900a 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn @@ -16,7 +16,6 @@ import("//foundation/multimedia/media_library/media_library.gni") group("media_library_fuzztest") { testonly = true deps = [ - "medialibraryphotoeditsizeoperation_fuzzer:MediaLibraryPhotoEditSizeOperationFuzzTest" "media_bgtask_aging_task_fuzzer:MediaBgtaskAgingTaskFuzzTest", "mediabgtaskmgrappbgtaskschedulestub_fuzzer:MediaBgtaskMgrAppBgtaskScheduleStubFuzzTest", "mediabgtaskmgrappopsconnectability_fuzzer:MediaBgtaskMgrAppOpsConnectAbilityFuzzTest", @@ -65,6 +64,7 @@ group("media_library_fuzztest") { "medialibrarymtpptpspecialhandles_fuzzer:MediaLibraryMtpPtpSpecialHandlesFuzzTest", "medialibrarymultistagescapture_fuzzer:MediaLibraryMultistagesCaptureFuzzTest", "medialibrarymultistagesdeferredcapture_fuzzer:MediaLibraryMultistagesDeferredCaptureFuzzTest", + "medialibraryphotoeditsizeoperation_fuzzer:MediaLibraryPhotoEditSizeOperationFuzzTest", "medialibraryrefreshmanager_fuzzer:MediaLibraryRefreshManagerFuzzTest", "medialibraryrestore_fuzzer:MediaLibraryRestoreFuzzTest", "medialibraryserviceextension_fuzzer:MediaLibraryServiceExtensionFuzzTest", diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn index 4f2abcb635..fcaea2d753 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. +# Copyright (c) 2024 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -19,14 +19,11 @@ ohos_fuzztest("MediaLibraryPhotoEditSizeOperationFuzzTest") { fuzz_config_file = "." include_dirs = [ - ".", "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include", - "${MEDIALIB_INNERKITS_PATH}/inner_api/media_library_helper/include", + "${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include", ] - sources = [ - "./media_library_photo_edit_size_operation_fuzzer.cpp", - ] + sources = [ "./media_library_photo_edit_sizeo_peration_fuzzer.cpp" ] deps = [ "${MEDIALIB_INNERKITS_PATH}/media_library_helper:media_library", @@ -34,36 +31,31 @@ ohos_fuzztest("MediaLibraryPhotoEditSizeOperationFuzzTest") { ] external_deps = [ - "hitrace:hitrace_meter", - "access_token:libaccesstoken_sdk", - "access_token:libprivacy_sdk", - "access_token:libnativetoken_shared", - "access_token:libtokensetproc_shared", + "ability_base:configuration", + "ability_base:want", "ability_base:zuri", "ability_runtime:ability_context_native", "ability_runtime:ability_manager", "ability_runtime:abilitykit_native", "ability_runtime:app_context", + "ability_runtime:app_manager", + "ability_runtime:dataobs_manager", + "ability_runtime:runtime", "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", "data_share:datashare_common", + "data_share:datashare_consumer", "data_share:datashare_provider", - "device_manager:devicemanagersdk", - "dfs_service:cloudsync_kit_inner", "hilog:libhilog", + "hitrace:hitrace_meter", + "image_framework:image_native", "ipc:ipc_single", "kv_store:distributeddata_inner", "napi:ace_napi", "player_framework:media_client", "relational_store:native_rdb", "relational_store:rdb_data_share_adapter", - "ability_runtime:dataobs_manager", - "app_file_service:fileuri_native", - "data_share:datashare_consumer", - "e2fsprogs:libext2_uuid", - "image_framework:image_native", "user_file_service:file_access_extension_ability_kit", - "ipc:ipc_napi", ] -} \ No newline at end of file +} -- Gitee From 4fe99997e492a9fb842d9142588c2cca705f6ce1 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Mon, 28 Jul 2025 12:27:04 +0000 Subject: [PATCH 06/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- .../media_library_photo_edit_size_operation_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp index fe67a54039..60c2615e13 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp @@ -292,7 +292,7 @@ extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) return 0; } -extern "C"LLVMFuzzerTestOneInput(const unit8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const unit8_t *data, size_t size) { FuzzedDataProvider fdp(data, size); OHOS::Media::provider = &fdp; -- Gitee From 9115dab4a686171093a726f0ff0caf525cf71b91 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Tue, 29 Jul 2025 01:53:13 +0000 Subject: [PATCH 07/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- .../fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn index fcaea2d753..5e880658f0 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn @@ -23,7 +23,7 @@ ohos_fuzztest("MediaLibraryPhotoEditSizeOperationFuzzTest") { "${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include", ] - sources = [ "./media_library_photo_edit_sizeo_peration_fuzzer.cpp" ] + sources = [ "./media_library_photo_edit_size_operation_fuzzer.cpp" ] deps = [ "${MEDIALIB_INNERKITS_PATH}/media_library_helper:media_library", -- Gitee From da49952d93ce30ddedee042929629a09f8ca9d66 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Tue, 29 Jul 2025 02:47:29 +0000 Subject: [PATCH 08/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- .../fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn index 5e880658f0..b6747780f9 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn @@ -19,6 +19,7 @@ ohos_fuzztest("MediaLibraryPhotoEditSizeOperationFuzzTest") { fuzz_config_file = "." include_dirs = [ + ".", "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include", "${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include", ] -- Gitee From ffd60d95cffdf53854fdea29fafed54f93f94dc9 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Tue, 29 Jul 2025 03:11:39 +0000 Subject: [PATCH 09/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- .../fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn index b6747780f9..197030de0f 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn @@ -21,6 +21,7 @@ ohos_fuzztest("MediaLibraryPhotoEditSizeOperationFuzzTest") { include_dirs = [ ".", "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include", + "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include/operation" "${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include", ] -- Gitee From f69744e1cb09ba969142d25bbd4ac48f5eeee730 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Tue, 29 Jul 2025 03:26:02 +0000 Subject: [PATCH 10/12] =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- .../fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn index 197030de0f..eedddd3a1b 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn @@ -21,7 +21,7 @@ ohos_fuzztest("MediaLibraryPhotoEditSizeOperationFuzzTest") { include_dirs = [ ".", "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include", - "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include/operation" + "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include/operation", "${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include", ] -- Gitee From 1a650eea2484d14928f3767c8322fec230d866a8 Mon Sep 17 00:00:00 2001 From: renchunxu Date: Tue, 29 Jul 2025 04:27:25 +0000 Subject: [PATCH 11/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: renchunxu --- .../BUILD.gn | 4 +- ...brary_photo_edit_size_operation_fuzzer.cpp | 146 +++++++++--------- ...library_photo_edit_size_operation_fuzzer.h | 26 ++-- 3 files changed, 90 insertions(+), 86 deletions(-) diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn index eedddd3a1b..4783fb9001 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -19,9 +19,7 @@ ohos_fuzztest("MediaLibraryPhotoEditSizeOperationFuzzTest") { fuzz_config_file = "." include_dirs = [ - ".", "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include", - "${MEDIALIB_INNERKITS_PATH}/medialibrary_data_extension/include/operation", "${MEDIALIB_INTERFACES_PATH}/inner_api/media_library_helper/include", ] diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp index 60c2615e13..dc571a911b 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.cpp @@ -1,17 +1,17 @@ /* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #include "media_library_photo_edit_size_operation_fuzzer.h" @@ -28,7 +28,7 @@ #include "medialibrary_data_manager.h" #include "medialibrary_unistore_manager.h" #include "medialibrary_kvstore_manager.h" -#include "medialibrary_photo_operation.h" +#include "medialibrary_photo_operations.h" #include "media_file_utils.h" #include "result_set_utils.h" @@ -36,8 +36,8 @@ namespace OHOS { namespace Media { using namespace std; using namespace OHOS::NativeRdb; -using namespace OHO::DataShare; -using OHOS::DataSharePredicates; +using namespace OHOS::DataShare; +using OHOS::DataShare::DataSharePredicates; struct PhotoMode { string path; @@ -57,45 +57,44 @@ static const std::string FORMAT_VERSION_VALUE = "0"; static const std::string CAMERA_BUNDLE_NAME = "com.example.hmos.camera"; FuzzedDataProvider *provider = nullptr; -std::shared_ptr grdbStore; +std::shared_ptr g_rdbStore; -static const unit8_t BUF[] = { +static const uint8_t BUF[] = { 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 96, 0, 96, 0, 0, 255, 219, 0, 67, 0, 8, 6, 6, 7, 6, 5, 8, 7, 7, 7, 9, 9, 8, 10, 12, 20, 13, 12, 11, 11, 12, 25, 18, 19, 15, 20, 29, 26, 31, 30, 29, 26, 28, 28, 32, 36, 46, - 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 57, 61, 56, 50, 60, 46, 51, 52, 50, - 255, + 39, 32, 34, 44, 35, 28, 28, 40, 55, 41, 44, 48, 49, 52, 52, 52, 31, 39, 57, 61, 56, 50, 60, 46, 51, 52, 50, 255, 219, 0, 67, 1, 9, 9, 9, 12, 11, 12, 24, 13, 13, 24, 50, 33, 28, 33, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 255, 192, 0, 17, 8, 0, 132, 0, 132, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, + 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, + 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, + 113, 20, 50, 129, 145, 161, 8, 35, 66, 177, 193, 21, 82, 209, 240, 36, 51, 98, 114, 130, 9, 10, 22, 23, 24, 25, 26, + 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, + 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 131, 132, 133, 134, 135, 136, 137, + 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, + 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, + 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 196, 0, 31, + 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 17, 0, + 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, 113, 19, 34, 50, + 129, 8, 20, 66, 145, 161, 177, 193, 9, 35, 51, 82, 240, 21, 98, 114, 209, 10, 22, 36, 52, 225, 37, 241, 23, 24, 25, + 26, 38, 39, 40, 41, 42, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, + 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 130, 131, 132, 133, 134, 135, 136, 137, + 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, + 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, + 226, 227, 228, 229, 230, 231, 232, 233, 234, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 218, 0, 12, 3, 1, 0, + 2, 17, 3, 17, 0, 63, 0, 244, 74, 40, 162, 191, 35, 62, 148, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, + 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, + 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, + 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, + 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, + 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, + 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, + 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, + 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, + 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, + 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, + 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 40, 162, + 138, 0, 40, 162, 138, 0, 40, 162, 138, 0, 255, 217 }; string g_fileName = ""; @@ -108,14 +107,14 @@ vector g_filePaths = { }; int32_t WriteFile(int destfd) { write(destfd, BUF, sizeof(BUF)); - retiurn E_OK; + return E_OK; } string CreateCacheFile() { string cacheFileName = g_fileName; - string uri = PhotoColumn::PHOTO_CACH_URI_PREFIX + cacheFileName; - MediaFileUtils::UriAppendKeyValue(uri, URI_PARAM_API_VERSION, to_string(MEDIA_API_VERSION_V10)) + string uri = PhotoColumn::PHOTO_CACHE_URI_PREFIX + cacheFileName; + MediaFileUtils::UriAppendKeyValue(uri, URI_PARAM_API_VERSION, to_string(MEDIA_API_VERSION_V10)); Uri openCacheUri(uri); MediaLibraryCommand cmd(openCacheUri); int32_t cacheFileFd = MediaLibraryDataManager::GetInstance()->OpenFile(cmd, "w"); @@ -130,6 +129,13 @@ int32_t CreatePhotoAsset() MediaLibraryApi::API_10); OHOS::NativeRdb::ValuesBucket values; string displayName = g_fileName; + values.PutString(MediaColumn::MEDIA_NAME, displayName); + values.PutInt(MediaColumn::MEDIA_TYPE, MediaType::MEDIA_TYPE_IMAGE); + cmd.SetValueBucket(values); + int32_t ret = MediaLibraryPhotoOperations::Create(cmd); + if (ret < 0) { + return ret; + } return ret; } @@ -141,13 +147,13 @@ void SubmitCache(DataShareValuesBucket &valuesBucket, bool isAddWater, bool isEd // 预留 } string assetUri; - MediaLibraryDataManger::GetInstance()->InsertExt(submitCacheCmd, valuesBucket, assetUri); + MediaLibraryDataManager::GetInstance()->InsertExt(submitCacheCmd, valuesBucket, assetUri); } DataShareValuesBucket GetValuesBucket(int32_t fileId, std::string cacheFileName, bool isSetEditData) { DataShareValuesBucket valuesBucket; - valuesBucket.Put(PhootoColumn::MEDIA_ID, fileId); + valuesBucket.Put(PhotoColumn::MEDIA_ID, fileId); valuesBucket.Put(CACHE_FILE_NAME, cacheFileName); if (isSetEditData) { valuesBucket.Put(EDIT_DATA, EDITDATA_VALUE); @@ -160,10 +166,10 @@ DataShareValuesBucket GetValuesBucket(int32_t fileId, std::string cacheFileName, PhotoMode GetPhotoMode(int fileId) { PhotoMode photoMode; - vector colums = { PhotoColumn::MEDIA_FILE_PATH, PhotoColum::PHOTO_EDIT_TIME }; + vector columns = { PhotoColumn::MEDIA_FILE_PATH, PhotoColumn::PHOTO_EDIT_TIME }; MediaLibraryCommand cmd(OperationObject::FILESYSTEM_PHOTO, OperationType::QUERY, MediaLibraryApi::API_10); - cmd.GetAbsRdbPredicates()->EqualTo(PhotoColum::MEDIA_ID, to_string(fileId)); + cmd.GetAbsRdbPredicates()->EqualTo(PhotoColumn::MEDIA_ID, to_string(fileId)); auto resultSet = g_rdbStore->Query(cmd, columns); resultSet->GoToFirstRow(); photoMode.path = GetStringVal(PhotoColumn::MEDIA_FILE_PATH, resultSet); @@ -186,7 +192,7 @@ TakePhotoResult TakePhotoMock(bool isAddWater) photoResult.fileId = fileId; photoResult.path = path; DataShareValuesBucket valuesBucket; - valuesBucket.Put(PhotoColum::MEDIA_ID, fileId); + valuesBucket.Put(PhotoColumn::MEDIA_ID, fileId); valuesBucket.Put(CACHE_FILE_NAME, cacheFileName); if (!isAddWater) { SubmitCache(valuesBucket, isAddWater, false); @@ -203,7 +209,7 @@ void EditPhoto(TakePhotoResult editResult, bool isSetEditData, bool isAddWater) { string cacheFileName = CreateCacheFile(); DataShareValuesBucket valuesBucket = GetValuesBucket(editResult.fileId, cacheFileName, isSetEditData); - submitCache(valuesBucket, isAddWater, true); + SubmitCache(valuesBucket, isAddWater, true); } bool IsEdited(int fileId) @@ -241,8 +247,8 @@ static void PhotoEditSizeOperationTest() PhotoEditSizeOperation::CalSingleEditDataSize(g_fileIdStr.c_str(), g_filePath); PhotoEditSizeOperation::GetFileIdByCloudPath(g_rdbStore, g_fileIdStr, g_filePath); - PhotoEditSizeOperation::GetFileIdsAndPathS(g_rdbStore, g_fileIds, g_fileIds, g_filePaths, - startFileId, hasMore, limitCount); + PhotoEditSizeOperation::GetFileIdsAndPathS(g_rdbStore, g_fileIds, g_filePaths, + startFileId, hasMore, limitCount); PhotoEditSizeOperation::UpdateMediaSizeFromStorage(); } @@ -250,13 +256,13 @@ static void SetTables() { vector createTableSqlList = { Media::PhotoColumn::CREATE_PHOTO_TABLE }; for (auto &createTableSql : createTableSqlList) { - CHECK_AND_RETURN_LOG(g_rdbStore != nullptr, "g_rdbStore is null"); + CHECK_AND_RETURN_LOG(g_rdbStore != nullptr, "g_rdbStore is null."); int32_t ret = g_rdbStore->ExecuteSql(createTableSql); if (ret != NativeRdb::E_OK) { - MEDIA_ERR_LOG("Execute sql %{private}s failed", createTableSql.c_str()); + MEDIA_ERR_LOG("Execute sql %{private}s failed.", createTableSql.c_str()); return; } - MEDIA_DEBUG_LOG("Execute Sql %{private}s success", createTableSql.c_str); + MEDIA_DEBUG_LOG("Execute sql %{private}s success.", createTableSql.c_str()); } } @@ -264,21 +270,21 @@ static void Init() { auto stageContext = std::make_shared(); auto abilityContextImpl = std::make_shared(); - abilityContestImpl->SetStageContext(stageContext); + abilityContextImpl->SetStageContext(stageContext); int32_t sceneCode = 0; auto ret = Media::MediaLibraryDataManager::GetInstance()->InitMediaLibraryMgr(abilityContextImpl, abilityContextImpl, sceneCode); - CHECK_AND_RETURN_LOG(ret == NativeRdb::E_OK, "InitMediaLibrary Mgr failed, ret : %{public}d", ret); + CHECK_AND_RETURN_LOG(ret == NativeRdb::E_OK, "InitMediaLibrary Mgr failed, ret: %{public}d.", ret); auto rdbStore = Media::MediaLibraryUnistoreManager::GetInstance().GetRdbStore(); if (rdbStore == nullptr) { - MEDIA_ERR_LOG("rdbStore is nullptr"); + MEDIA_ERR_LOG("rdbStore is nullptr."); return; } g_rdbStore = rdbStore; SetTables(); } -static inline void CleatKvStore() +static inline void ClearKvStore() { Media::MediaLibraryKvStoreManager::GetInstance().CloseAllKvStore(); } @@ -292,14 +298,14 @@ extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) return 0; } -extern "C" int LLVMFuzzerTestOneInput(const unit8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { FuzzedDataProvider fdp(data, size); OHOS::Media::provider = &fdp; if (data == nullptr) { return 0; } - OHOS::Media::RandomDatainit(); + OHOS::Media::RandomDataInit(); OHOS::Media::PhotoEditSizeOperationTest(); OHOS::Media::ClearKvStore(); return 0; diff --git a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.h b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.h index 84e255ad3d..512414d5a5 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.h +++ b/frameworks/innerkitsimpl/test/fuzztest/medialibraryphotoeditsizeoperation_fuzzer/media_library_photo_edit_size_operation_fuzzer.h @@ -1,17 +1,17 @@ /* -* Copyright (c) 2025 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ #ifndef NOTIFYCHANGE_FUZZER_H #define NOTIFYCHANGE_FUZZER_H -- Gitee From 60f6cae4d5d74405f6bdc8ff87cb522f7a4db15c Mon Sep 17 00:00:00 2001 From: renchunxu Date: Tue, 5 Aug 2025 04:25:23 +0000 Subject: [PATCH 12/12] fix Signed-off-by: renchunxu --- frameworks/innerkitsimpl/test/fuzztest/BUILD.gn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn index e630a5900a..7c45fe9986 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/BUILD.gn @@ -33,6 +33,7 @@ group("media_library_fuzztest") { "medialibrarycloudmediaassetmanager_fuzzer:MediaLibraryCloudMediaAssetManagerFuzzTest", "medialibrarycommon_fuzzer:MediaLibraryCommonFuzzTest", "medialibrarydfx_fuzzer:MediaLibraryDfxFuzzTest", + "medialibraryduplicatephotooperation_fuzzer:MediaLibraryDuplicatePhotoOperationFuzzTest", "medialibraryenhancement_fuzzer:MediaLibraryEnhancementFuzzTest", "medialibraryextension_fuzzer:MediaLibraryExtensionFuzzTest", "medialibraryextensionbatchinsert_fuzzer:MediaLibraryExtensionBatchInsertFuzzTest", @@ -64,7 +65,7 @@ group("media_library_fuzztest") { "medialibrarymtpptpspecialhandles_fuzzer:MediaLibraryMtpPtpSpecialHandlesFuzzTest", "medialibrarymultistagescapture_fuzzer:MediaLibraryMultistagesCaptureFuzzTest", "medialibrarymultistagesdeferredcapture_fuzzer:MediaLibraryMultistagesDeferredCaptureFuzzTest", - "medialibraryphotoeditsizeoperation_fuzzer:MediaLibraryPhotoEditSizeOperationFuzzTest", + "medialibraryphotoeditsizeoperation_fuzzer:MediaLibraryPhotoEditSizeOperationFuzzTest", "medialibraryrefreshmanager_fuzzer:MediaLibraryRefreshManagerFuzzTest", "medialibraryrestore_fuzzer:MediaLibraryRestoreFuzzTest", "medialibraryserviceextension_fuzzer:MediaLibraryServiceExtensionFuzzTest", -- Gitee