From 16807deb027bc6a86888e60200bba9c57724e7f8 Mon Sep 17 00:00:00 2001 From: m0_54007497 Date: Wed, 3 Sep 2025 09:56:14 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6?= =?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: m0_54007497 --- frameworks/c/drm_capi/native_mediakeysystem.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/frameworks/c/drm_capi/native_mediakeysystem.cpp b/frameworks/c/drm_capi/native_mediakeysystem.cpp index 347a74b..d207957 100644 --- a/frameworks/c/drm_capi/native_mediakeysystem.cpp +++ b/frameworks/c/drm_capi/native_mediakeysystem.cpp @@ -30,7 +30,18 @@ #include "drm_error_code.h" using namespace OHOS::DrmStandard; +bool isHex(const std::string& str) { + if (str.empty()) { + return false; + } + for (char c : str) { + if (!std::isxdigit(c)) { + return false; + } + } + return true; +} bool OH_MediaKeySystem_IsSupported(const char *uuid) { DRM_INFO_LOG("OH_MediaKeySystem_IsSupported enter."); @@ -109,6 +120,9 @@ Drm_ErrCode OH_MediaKeySystem_GetMediaKeySystems(DRM_MediaKeySystemDescription * for (size_t i = 0; i < sizeof(description[times].uuid) * BASE_CONVERSION_OPERATOR; i += BASE_CONVERSION_OPERATOR) { std::string byteStr = it->second.substr(i, BASE_CONVERSION_OPERATOR); + if(!isHex(byteStr)){ + continue; + } uint8_t byte = static_cast(std::stoi(byteStr, nullptr, HEXADECIMAL)); description[times].uuid[i/BASE_CONVERSION_OPERATOR] = byte; } -- Gitee From 15439a8d8cf2ce00284f9b7646405e264acb3de6 Mon Sep 17 00:00:00 2001 From: m0_54007497 Date: Wed, 3 Sep 2025 14:25:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=91=8A=E8=AD=A6?= =?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: m0_54007497 --- .../c/drm_capi/native_mediakeysystem.cpp | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/frameworks/c/drm_capi/native_mediakeysystem.cpp b/frameworks/c/drm_capi/native_mediakeysystem.cpp index d207957..9d5f3bb 100644 --- a/frameworks/c/drm_capi/native_mediakeysystem.cpp +++ b/frameworks/c/drm_capi/native_mediakeysystem.cpp @@ -30,7 +30,7 @@ #include "drm_error_code.h" using namespace OHOS::DrmStandard; -bool isHex(const std::string& str) { +bool IsHex(const std::string& str) { if (str.empty()) { return false; } @@ -95,22 +95,11 @@ bool OH_MediaKeySystem_IsSupported3(const char *uuid, const char *mimeType, return isSupported; } -Drm_ErrCode OH_MediaKeySystem_GetMediaKeySystems(DRM_MediaKeySystemDescription *description, uint32_t *count) -{ - DRM_INFO_LOG("OH_MediaKeySystem_GetMediaKeySystems enter"); - DRM_CHECK_AND_RETURN_RET_LOG((description != nullptr), DRM_ERR_INVALID_VAL, "description is nullptr"); - DRM_CHECK_AND_RETURN_RET_LOG((count != nullptr), DRM_ERR_INVALID_VAL, "count is nullptr"); - std::map keySystemNames; - OHOS::sptr fatory = MediaKeySystemFactoryImpl::GetInstance(); - int32_t ret = fatory->GetMediaKeySystems(keySystemNames); - DRM_CHECK_AND_RETURN_RET_LOG((*count >= keySystemNames.size()), DRM_ERR_INVALID_VAL, - "GetMediaKeySystems failed because the count passed by is too small."); +static Drm_ErrCode FillDescriptions(DRM_MediaKeySystemDescription *description, const std::map &keySystemNames) { int32_t times = 0; - DRM_CHECK_AND_RETURN_RET_LOG((ret == DRM_ERR_OK), DRM_ERR_UNKNOWN, - "GetMediaKeySystems call Failed!"); for (auto it = keySystemNames.begin(); it != keySystemNames.end(); it++) { if (it->first.size() != 0) { - ret = strcpy_s(description[times].name, sizeof(description[times].name) - 1, it->first.c_str()); + int ret = strcpy_s(description[times].name, sizeof(description[times].name) - 1, it->first.c_str()); if (ret != 0) { DRM_ERR_LOG("OH_MediaKeySystem_GetMediaKeySystems memcpy_s description faild!"); return DRM_ERR_NO_MEMORY; @@ -129,10 +118,29 @@ Drm_ErrCode OH_MediaKeySystem_GetMediaKeySystems(DRM_MediaKeySystemDescription * } times++; } + return DRM_ERR_OK; +} + +Drm_ErrCode OH_MediaKeySystem_GetMediaKeySystems(DRM_MediaKeySystemDescription *description, uint32_t *count) +{ + DRM_INFO_LOG("OH_MediaKeySystem_GetMediaKeySystems enter"); + DRM_CHECK_AND_RETURN_RET_LOG((description != nullptr), DRM_ERR_INVALID_VAL, "description is nullptr"); + DRM_CHECK_AND_RETURN_RET_LOG((count != nullptr), DRM_ERR_INVALID_VAL, "count is nullptr"); + std::map keySystemNames; + OHOS::sptr fatory = MediaKeySystemFactoryImpl::GetInstance(); + int32_t ret = fatory->GetMediaKeySystems(keySystemNames); + DRM_CHECK_AND_RETURN_RET_LOG((ret == DRM_ERR_OK), DRM_ERR_UNKNOWN, "GetMediaKeySystems call Failed!"); + DRM_CHECK_AND_RETURN_RET_LOG((*count >= keySystemNames.size()), DRM_ERR_INVALID_VAL, "GetMediaKeySystems failed because the count passed by is too small."); if (keySystemNames.size() == 0) { DRM_ERR_LOG("plugin not exist."); return DRM_ERR_UNKNOWN; } + + Drm_ErrCode fillRet = FillDescriptions(description, keySystemNames); + if (fillRet != DRM_ERR_OK) { + return fillRet; + } + *count = keySystemNames.size(); return DRM_ERR_OK; } -- Gitee From bfecc170ef508c02b5307d953fcdd0e41916c0a4 Mon Sep 17 00:00:00 2001 From: m0_54007497 Date: Wed, 3 Sep 2025 14:26:31 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=A7=84=E8=8C=83=E5=8C=96=E4=BF=AE?= =?UTF-8?q?=E6=94=B9IsHEX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: m0_54007497 --- frameworks/c/drm_capi/native_mediakeysystem.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/c/drm_capi/native_mediakeysystem.cpp b/frameworks/c/drm_capi/native_mediakeysystem.cpp index 9d5f3bb..927a2fb 100644 --- a/frameworks/c/drm_capi/native_mediakeysystem.cpp +++ b/frameworks/c/drm_capi/native_mediakeysystem.cpp @@ -30,12 +30,14 @@ #include "drm_error_code.h" using namespace OHOS::DrmStandard; -bool IsHex(const std::string& str) { +static bool IsHex(const std::string& str) +{ if (str.empty()) { return false; } + for (char c : str) { - if (!std::isxdigit(c)) { + if (!std::isxdigit(c)) { return false; } } -- Gitee From cdbe82d0793487802b17da7fd4de54879cf3c439 Mon Sep 17 00:00:00 2001 From: m0_54007497 Date: Wed, 3 Sep 2025 14:35:34 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91=C2=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: m0_54007497 --- frameworks/c/drm_capi/native_mediakeysystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/c/drm_capi/native_mediakeysystem.cpp b/frameworks/c/drm_capi/native_mediakeysystem.cpp index 927a2fb..949ce92 100644 --- a/frameworks/c/drm_capi/native_mediakeysystem.cpp +++ b/frameworks/c/drm_capi/native_mediakeysystem.cpp @@ -111,8 +111,8 @@ static Drm_ErrCode FillDescriptions(DRM_MediaKeySystemDescription *description, for (size_t i = 0; i < sizeof(description[times].uuid) * BASE_CONVERSION_OPERATOR; i += BASE_CONVERSION_OPERATOR) { std::string byteStr = it->second.substr(i, BASE_CONVERSION_OPERATOR); - if(!isHex(byteStr)){ - continue; + if(!IsHex(byteStr)){ + return DRM_ERR_INVALID_VAL; } uint8_t byte = static_cast(std::stoi(byteStr, nullptr, HEXADECIMAL)); description[times].uuid[i/BASE_CONVERSION_OPERATOR] = byte; -- Gitee