diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn index fd6ed3eebf2201987bfd6c6ca2b87c82a52e58f6..da1ed29f842e9df19625ccbc8bddddb2665d59fa 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn @@ -18,5 +18,6 @@ group("fuzztest") { "dscreensinkhandler_fuzzer:fuzztest", "dscreensinkproxy_fuzzer:fuzztest", "dscreensourcehandler_fuzzer:fuzztest", + "dscreensourceproxy_fuzzer:fuzztest", ] } diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..848951530e59e66924e1f2184b8dc3f99aab8662 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DscreenSourceProxyFuzzTest") { + module_out_path = "distributed_screen/dscreensourceproxy" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "include/callback", + "${common_path}/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include/componentmanager", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dscreen_source_proxy_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_screen_utils", + "${fwk_services_path}/distributedhardwarefwkserviceimpl:distributedhardwarefwksvr_impl", + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenSourceProxyFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DscreenSourceProxyFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a5b970f771efdf67d5e0194a95c67443be756fd --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2022 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 "dscreen_source_proxy_fuzzer.h" + +#include +#include + +#include "dscreen_constants.h" +#include "dscreen_source_callback.h" +#include "dscreen_source_proxy.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DscreenSourceProxyHandlerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string params(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + std::string key(reinterpret_cast(data), size); + std::string value(reinterpret_cast(data), size); + int32_t eventCode = *(reinterpret_cast(data)); + std::string eventContent(reinterpret_cast(data), size); + std::string str(reinterpret_cast(data), size); + EnableParam param; + param.version = str; + param.attrs = str; + sptr callback = new DScreenSourceCallback(); + if (callback == nullptr) { + return; + } + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID); + std::shared_ptr dscreenSourceProxy = std::make_shared(remoteObject); + + dscreenSourceProxy->InitSource(params, callback); + dscreenSourceProxy->ReleaseSource(); + dscreenSourceProxy->RegisterDistributedHardware(devId, dhId, param, reqId); + dscreenSourceProxy->UnregisterDistributedHardware(devId, dhId, reqId); + dscreenSourceProxy->ConfigDistributedHardware(devId, dhId, key, value); + dscreenSourceProxy->DScreenNotify(devId, eventCode, eventContent); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenSourceProxyHandlerFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..6a8a9812ea6b49b47b35ec55bc32ed99e81a2146 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 DSCREEN_SOURCE_PROXY_FUZZER_H +#define DSCREEN_SOURCE_PROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "dscreen_source_proxy_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/screentransport/test/fuzztest/BUILD.gn b/services/screentransport/test/fuzztest/BUILD.gn index 02b6da6be0e40c75ba479ec2d3c5d1a30fa57893..1f508824a2d531c20eb962377a0fadae4b033466 100644 --- a/services/screentransport/test/fuzztest/BUILD.gn +++ b/services/screentransport/test/fuzztest/BUILD.gn @@ -16,6 +16,8 @@ group("fuzztest") { deps = [ "screendatachannel_fuzzer:fuzztest", + "screensinkprocessor_fuzzer:fuzztest", + "screensinktrans_fuzzer:fuzztest", "screensourceprocessor_fuzzer:fuzztest", "screensourcetrans_fuzzer:fuzztest", ] diff --git a/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/BUILD.gn b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4648931cc5c1f74141674d276e716e400f75ff6e --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/BUILD.gn @@ -0,0 +1,82 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ScreenSinkProcessorFuzzTest") { + module_out_path = "distributed_screen/screensinkprocessor" + + fuzz_config_file = "${services_path}/screentransport/test/fuzztest/screensinkprocessor_fuzzer" + + include_dirs = [ + "//third_party/json/include", + "//foundation/graphic/standard/interfaces/innerkits/surface", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "./include", + "${services_path}/screentransport/test/unittest/screentranstestutils/include", + "${common_path}/include", + "${services_path}/common/databuffer/include", + "${services_path}/common/screen_channel/include", + "${services_path}/common/utils/include", + "${services_path}/screentransport/screendatachannel/include", + "${services_path}/screentransport/screensourcetrans/include", + "${services_path}/screentransport/screensinkprocessor/include", + "${services_path}/screentransport/screensinktrans/include", + "${services_path}/screentransport/screensinkprocessor/include", + "${services_path}/screentransport/screensinkprocessor/decoder/include", + "${services_path}/softbusadapter/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "screen_sink_processor_fuzzer.cpp" ] + + deps = [ + "${fwk_utils_path}:distributedhardwareutils", + "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", + "//foundation/graphic/standard/frameworks/surface:surface", + "//utils/native/base:utils", + ] + + external_deps = [ + "dsoftbus_standard:softbus_client", + "hiviewdfx_hilog_native:libhilog", + "multimedia_media_standard:media_client", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"ScreenSinkProcessorFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ScreenSinkProcessorFuzzTest" ] +} +############################################################################### diff --git a/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/corpus/init b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/project.xml b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/screen_sink_processor_fuzzer.cpp b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/screen_sink_processor_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06e3606979540b2c28f8d55c2414e9e926cd2bb4 --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/screen_sink_processor_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2022 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 "screen_sink_processor_fuzzer.h" + +#include +#include +#include + +#include "image_sink_processor.h" +#include "screen_sink_trans.h" + +namespace OHOS { +namespace DistributedHardware { +void ScreenSinkProcessorFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::shared_ptr imageSinkProcessor = std::make_shared(); + std::shared_ptr param = std::make_shared(); + uint32_t screenWidth = *(reinterpret_cast(data)); + uint32_t screenHeight = *(reinterpret_cast(data)); + uint32_t videoWidth = *(reinterpret_cast(data)); + uint32_t videoHeight = *(reinterpret_cast(data)); + param->SetScreenWidth(screenWidth); + param->SetScreenHeight(screenHeight); + param->SetVideoWidth(videoWidth); + param->SetScreenHeight(videoHeight); + std::shared_ptr imageListener = std::make_shared(); + std::string name(reinterpret_cast(data), size); + sptr surface = Surface::CreateSurfaceAsConsumer(name); + size_t capacity = size; + std::shared_ptr screenData = std::make_shared(capacity); + + imageSinkProcessor->SetImageSurface(surface); + imageSinkProcessor->ConfigureImageProcessor(*param, *param, imageListener); + imageSinkProcessor->ProcessImage(screenData); + imageSinkProcessor->StartImageProcessor(); + imageSinkProcessor->StopImageProcessor(); + imageSinkProcessor->ReleaseImageProcessor(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::ScreenSinkProcessorFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/screen_sink_processor_fuzzer.h b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/screen_sink_processor_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e56562c92819d15a5cea5dba01b42c8630b04158 --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinkprocessor_fuzzer/screen_sink_processor_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 SCREEN_SINK_PROCESSOR_FUZZER_H +#define SCREEN_SINK_PROCESSOR_FUZZER_H + +#define FUZZ_PROJECT_NAME "screen_sink_processor_fuzzer" + +#endif \ No newline at end of file diff --git a/services/screentransport/test/fuzztest/screensinktrans_fuzzer/BUILD.gn b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..97ed2768bed195c4dbecc06ad0970cebaf9ab210 --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 2022 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ScreenSinkTransFuzzTest") { + module_out_path = "distributed_screen/screensinktrans" + + fuzz_config_file = + "${services_path}/screentransport/test/fuzztest/screensinktrans_fuzzer" + + include_dirs = [ + "//third_party/json/include", + "//foundation/graphic/standard/interfaces/innerkits/surface", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "./include", + "${services_path}/screentransport/test/unittest/screentranstestutils/include", + "${common_path}/include", + "${services_path}/common/databuffer/include", + "${services_path}/common/screen_channel/include", + "${services_path}/common/utils/include", + "${services_path}/screentransport/screendatachannel/include", + "${services_path}/screentransport/screensourcetrans/include", + "${services_path}/screentransport/screensinktrans/include", + "${services_path}/screentransport/screensinkprocessor/include", + "${services_path}/screentransport/screensinkprocessor/decoder/include", + "${services_path}/softbusadapter/include", + "${services_path}/screenservice/sinkservice/screenregionmgr/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "screen_sink_trans_fuzzer.cpp" ] + + deps = [ + "${fwk_utils_path}:distributedhardwareutils", + "${services_path}/screenservice/sinkservice:distributed_screen_sink", + "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", + "//foundation/graphic/standard/frameworks/surface:surface", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"ScreenSinkTransFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "dsoftbus_standard:softbus_client", + "hiviewdfx_hilog_native:libhilog", + "multimedia_media_standard:media_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ScreenSinkTransFuzzTest" ] +} +############################################################################### diff --git a/services/screentransport/test/fuzztest/screensinktrans_fuzzer/corpus/init b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 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/services/screentransport/test/fuzztest/screensinktrans_fuzzer/project.xml b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/screentransport/test/fuzztest/screensinktrans_fuzzer/screen_sink_trans_fuzzer.cpp b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/screen_sink_trans_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c7a4717f539fd25a835662a0a7bd368f4113258 --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/screen_sink_trans_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 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 "screen_sink_trans_fuzzer.h" + +#include +#include +#include + +#include "screenregion.h" +#include "screen_sink_trans.h" +#include "screentrans_test_utils.h" + +namespace OHOS { +namespace DistributedHardware { +void ScreenSinkTransFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::shared_ptr screenSinkTrans = std::make_shared(); + std::shared_ptr param = std::make_shared(); + uint32_t screenWidth = *(reinterpret_cast(data)); + uint32_t screenHeight = *(reinterpret_cast(data)); + uint32_t videoWidth = *(reinterpret_cast(data)); + uint32_t videoHeight = *(reinterpret_cast(data)); + param->SetScreenWidth(screenWidth); + param->SetScreenHeight(screenHeight); + param->SetVideoWidth(videoWidth); + param->SetScreenHeight(videoHeight); + std::string peerDevId(reinterpret_cast(data), size); + std::string remoteDevId(reinterpret_cast(data), size); + uint64_t screenId = *(reinterpret_cast(data)); + uint64_t displayId = *(reinterpret_cast(data)); + std::shared_ptr callBack = + std::make_shared(remoteDevId, screenId, displayId); + std::string name(reinterpret_cast(data), size); + sptr surface = Surface::CreateSurfaceAsConsumer(name); + + screenSinkTrans->SetUp(*param, *param, peerDevId); + screenSinkTrans->SetImageSurface(surface); + screenSinkTrans->Start(); + screenSinkTrans->RegisterStateCallback(callBack); + screenSinkTrans->Stop(); + screenSinkTrans->Release(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::ScreenSinkTransFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/services/screentransport/test/fuzztest/screensinktrans_fuzzer/screen_sink_trans_fuzzer.h b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/screen_sink_trans_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..10783fc031a707cd6d48bc599c235c2f1767647e --- /dev/null +++ b/services/screentransport/test/fuzztest/screensinktrans_fuzzer/screen_sink_trans_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 SCREEN_SINK_TRANS_FUZZER_H +#define SCREEN_SINK_TRANS_FUZZER_H + +#define FUZZ_PROJECT_NAME "screen_sink_trans_fuzzer" + +#endif \ No newline at end of file