From 24a03a90f8e48277b9fdc4cd4f4be4627b7efb5d Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Wed, 17 Jul 2024 17:58:01 +0800 Subject: [PATCH 1/3] =?UTF-8?q?DAUDIO=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhonglufu --- common/src/daudio_latency_test.cpp | 6 +++++- common/test/unittest/src/daudio_utils_test.cpp | 1 + .../sinkproxyinitsink_fuzzer/sinkproxyinitsink_fuzzer.cpp | 2 +- .../sourceproxyinitsource_fuzzer.cpp | 4 ++-- services/audioclient/micclient/src/dmic_client.cpp | 4 ++++ services/audioclient/spkclient/src/dspeaker_client.cpp | 4 ++++ services/audiohdiproxy/src/daudio_manager_callback.cpp | 4 ++++ 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/common/src/daudio_latency_test.cpp b/common/src/daudio_latency_test.cpp index d88024b9..7dcd55df 100644 --- a/common/src/daudio_latency_test.cpp +++ b/common/src/daudio_latency_test.cpp @@ -24,7 +24,7 @@ #undef DH_LOG_TAG #define DH_LOG_TAG "DAudioLatencyTest" - +#define MAXSIZE 8192 namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(DAudioLatencyTest); @@ -69,6 +69,10 @@ int32_t DAudioLatencyTest::AddRecordTime(const int64_t recordBeepTime) bool DAudioLatencyTest::IsFrameHigh(const int16_t *audioData, const int32_t size, int32_t threshhold) { + if (size > MAXSIZE) { + DHLOGI("size=%{public}d is over range", size); + return false; + } int32_t max = 0; for (int32_t i = 0; i < size; i++) { int16_t f = abs(audioData[i]); diff --git a/common/test/unittest/src/daudio_utils_test.cpp b/common/test/unittest/src/daudio_utils_test.cpp index 37b60bc9..7c2eb220 100644 --- a/common/test/unittest/src/daudio_utils_test.cpp +++ b/common/test/unittest/src/daudio_utils_test.cpp @@ -164,6 +164,7 @@ HWTEST_F(DAudioUtilsTest, DAudioUtilTest_002, TestSize.Level1) cJSON_AddStringToObject(jsonObj, "one", "one"); cJSON_AddNumberToObject(jsonObj, "two", 2); CJsonParamCheck(jsonObj, keys); + cJSON_Delete(jsonObj); int64_t tvSec; int64_t tvNSec; diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/sinkproxyinitsink_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/sinkproxyinitsink_fuzzer.cpp index 465eeb80..84fc5dcf 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/sinkproxyinitsink_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkproxyinitsink_fuzzer/sinkproxyinitsink_fuzzer.cpp @@ -41,7 +41,7 @@ void SinkProxyInitSinkFuzzTest(const uint8_t* data, size_t size) return; } std::shared_ptr dAudioProxy = std::make_shared(remoteObject); - sptr dAudioSinkIpcCallback = new DAudioSinkIpcCallback(); + sptr dAudioSinkIpcCallback(new DAudioSinkIpcCallback()); dAudioProxy->InitSink(params, dAudioSinkIpcCallback); } } diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.cpp index 18edf117..0ca487bd 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sourceproxyinitsource_fuzzer/sourceproxyinitsource_fuzzer.cpp @@ -42,8 +42,8 @@ void SourceProxyInitSourceFuzzTest(const uint8_t* data, size_t size) return; } std::shared_ptr dAudioProxy = std::make_shared(remoteObject); - sptr callback = new DAudioIpcCallback(); - + sptr callback(new DAudioIpcCallback()); + dAudioProxy->InitSource(params, callback); } } diff --git a/services/audioclient/micclient/src/dmic_client.cpp b/services/audioclient/micclient/src/dmic_client.cpp index c7a7605f..4796eb75 100644 --- a/services/audioclient/micclient/src/dmic_client.cpp +++ b/services/audioclient/micclient/src/dmic_client.cpp @@ -319,6 +319,10 @@ void DMicClient::OnReadData(size_t length) DHLOGE("Audio data length is not equal to buflength. datalength: %{public}" PRIu64 ", bufLength: %{public}" PRIu64, capacity, bufLength); } + if (audioData->Capacity() < bufDesc.bufLength) { + DHLOGE("audio data size smaller than bufDesc."); + return; + } if (memcpy_s(audioData->Data(), audioData->Capacity(), bufDesc.buffer, bufDesc.bufLength) != EOK) { DHLOGE("Copy audio data failed."); } diff --git a/services/audioclient/spkclient/src/dspeaker_client.cpp b/services/audioclient/spkclient/src/dspeaker_client.cpp index eac62d1d..7719524e 100644 --- a/services/audioclient/spkclient/src/dspeaker_client.cpp +++ b/services/audioclient/spkclient/src/dspeaker_client.cpp @@ -137,6 +137,10 @@ void DSpeakerClient::OnWriteData(size_t length) DHLOGE("Audio data length is not equal to buflength. datalength: %{public}" PRIu64 ", bufLength: %{public}" PRIu64, capacity, bufLength); } + if (bufDesc.bufLength < audioData->Capacity()) { + DHLOGE("bufDesc data size smaller than audio capacity."); + return; + } if (memcpy_s(bufDesc.buffer, bufDesc.bufLength, audioData->Data(), audioData->Capacity()) != EOK) { DHLOGE("Copy audio data failed."); } diff --git a/services/audiohdiproxy/src/daudio_manager_callback.cpp b/services/audiohdiproxy/src/daudio_manager_callback.cpp index ce50485e..8dd4082d 100644 --- a/services/audiohdiproxy/src/daudio_manager_callback.cpp +++ b/services/audiohdiproxy/src/daudio_manager_callback.cpp @@ -178,6 +178,10 @@ int32_t DAudioManagerCallback::WriteStreamData(int32_t streamId, } std::shared_ptr audioData = std::make_shared(data.param.frameSize); + if (audioData->Capacity() < data.data.size()) { + DHLOGE("audio data capacity is smaller than data size"); + return HDF_FAILURE; + } int32_t ret = memcpy_s(audioData->Data(), audioData->Capacity(), data.data.data(), data.data.size()); if (ret != EOK) { DHLOGE("Copy audio data failed, error code %{public}d.", ret); -- Gitee From 3b666e9025ee9d83a74b81f4d8bf1770881f73d0 Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Fri, 19 Jul 2024 10:36:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?DAUDIO=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhonglufu --- services/audioclient/micclient/src/dmic_client.cpp | 4 ---- services/audioclient/spkclient/src/dspeaker_client.cpp | 4 ---- services/audiohdiproxy/src/daudio_manager_callback.cpp | 4 ---- 3 files changed, 12 deletions(-) diff --git a/services/audioclient/micclient/src/dmic_client.cpp b/services/audioclient/micclient/src/dmic_client.cpp index 4796eb75..c7a7605f 100644 --- a/services/audioclient/micclient/src/dmic_client.cpp +++ b/services/audioclient/micclient/src/dmic_client.cpp @@ -319,10 +319,6 @@ void DMicClient::OnReadData(size_t length) DHLOGE("Audio data length is not equal to buflength. datalength: %{public}" PRIu64 ", bufLength: %{public}" PRIu64, capacity, bufLength); } - if (audioData->Capacity() < bufDesc.bufLength) { - DHLOGE("audio data size smaller than bufDesc."); - return; - } if (memcpy_s(audioData->Data(), audioData->Capacity(), bufDesc.buffer, bufDesc.bufLength) != EOK) { DHLOGE("Copy audio data failed."); } diff --git a/services/audioclient/spkclient/src/dspeaker_client.cpp b/services/audioclient/spkclient/src/dspeaker_client.cpp index 7719524e..eac62d1d 100644 --- a/services/audioclient/spkclient/src/dspeaker_client.cpp +++ b/services/audioclient/spkclient/src/dspeaker_client.cpp @@ -137,10 +137,6 @@ void DSpeakerClient::OnWriteData(size_t length) DHLOGE("Audio data length is not equal to buflength. datalength: %{public}" PRIu64 ", bufLength: %{public}" PRIu64, capacity, bufLength); } - if (bufDesc.bufLength < audioData->Capacity()) { - DHLOGE("bufDesc data size smaller than audio capacity."); - return; - } if (memcpy_s(bufDesc.buffer, bufDesc.bufLength, audioData->Data(), audioData->Capacity()) != EOK) { DHLOGE("Copy audio data failed."); } diff --git a/services/audiohdiproxy/src/daudio_manager_callback.cpp b/services/audiohdiproxy/src/daudio_manager_callback.cpp index 8dd4082d..ce50485e 100644 --- a/services/audiohdiproxy/src/daudio_manager_callback.cpp +++ b/services/audiohdiproxy/src/daudio_manager_callback.cpp @@ -178,10 +178,6 @@ int32_t DAudioManagerCallback::WriteStreamData(int32_t streamId, } std::shared_ptr audioData = std::make_shared(data.param.frameSize); - if (audioData->Capacity() < data.data.size()) { - DHLOGE("audio data capacity is smaller than data size"); - return HDF_FAILURE; - } int32_t ret = memcpy_s(audioData->Data(), audioData->Capacity(), data.data.data(), data.data.size()); if (ret != EOK) { DHLOGE("Copy audio data failed, error code %{public}d.", ret); -- Gitee From 208fcb87973c2b6d23c196e035f9ef925f58d6bc Mon Sep 17 00:00:00 2001 From: zhonglufu Date: Fri, 19 Jul 2024 16:24:34 +0800 Subject: [PATCH 3/3] =?UTF-8?q?DAUDIO=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhonglufu --- common/src/daudio_latency_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/daudio_latency_test.cpp b/common/src/daudio_latency_test.cpp index 7dcd55df..ab420fd0 100644 --- a/common/src/daudio_latency_test.cpp +++ b/common/src/daudio_latency_test.cpp @@ -24,10 +24,11 @@ #undef DH_LOG_TAG #define DH_LOG_TAG "DAudioLatencyTest" -#define MAXSIZE 8192 namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(DAudioLatencyTest); +constexpr int32_t MAXSIZE = 8192; + DAudioLatencyTest::DAudioLatencyTest() { DHLOGI("DAudioLatencyTest constructed."); -- Gitee