From baee5b230ecbf1a6bb84b6f8b02c5c9d3c18136d Mon Sep 17 00:00:00 2001 From: wanghongen Date: Fri, 22 Aug 2025 18:21:20 +0800 Subject: [PATCH 1/5] =?UTF-8?q?6.0=E5=91=8A=E8=AD=A6=E6=B8=85=E9=9B=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wanghongen --- camera/metadata/src/metadata_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camera/metadata/src/metadata_utils.cpp b/camera/metadata/src/metadata_utils.cpp index d71a4318..056cff12 100644 --- a/camera/metadata/src/metadata_utils.cpp +++ b/camera/metadata/src/metadata_utils.cpp @@ -415,7 +415,7 @@ std::string MetadataUtils::EncodeToString(std::shared_ptr metada } common_metadata_header_t *meta = metadata->get(); - int32_t encodeDataLen = headerLength + (itemLen * meta->item_count) + meta->data_count; + int32_t encodeDataLen = static_cast(headerLength + (itemLen * meta->item_count) + meta->data_count); std::string s(encodeDataLen, '\0'); char *encodeData = &s[0]; ret = memcpy_s(encodeData, encodeDataLen, meta, headerLength); -- Gitee From fe3f6e67680d356d49c4744a4f636926b166014a Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Fri, 22 Aug 2025 10:40:23 +0000 Subject: [PATCH 2/5] update camera/metadata/src/metadata_utils.cpp. Signed-off-by: wanghongenaf --- camera/metadata/src/metadata_utils.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/camera/metadata/src/metadata_utils.cpp b/camera/metadata/src/metadata_utils.cpp index 056cff12..69471a95 100644 --- a/camera/metadata/src/metadata_utils.cpp +++ b/camera/metadata/src/metadata_utils.cpp @@ -402,12 +402,14 @@ bool MetadataUtils::WriteMetadata(const camera_metadata_item_t &item, MessagePar return bRet; } +static int32_t + std::string MetadataUtils::EncodeToString(std::shared_ptr metadata) { int32_t ret; - const int32_t headerLength = sizeof(common_metadata_header_t); - const int32_t itemLen = sizeof(camera_metadata_item_entry_t); - const int32_t itemFixedLen = static_cast(offsetof(camera_metadata_item_entry_t, data)); + const uint32_t headerLength = sizeof(common_metadata_header_t); + const uint32_t itemLen = sizeof(camera_metadata_item_entry_t); + const uint32_t itemFixedLen = offsetof(camera_metadata_item_entry_t, data); if (metadata == nullptr || metadata->get() == nullptr) { METADATA_ERR_LOG("MetadataUtils::EncodeToString Metadata is invalid"); @@ -415,7 +417,7 @@ std::string MetadataUtils::EncodeToString(std::shared_ptr metada } common_metadata_header_t *meta = metadata->get(); - int32_t encodeDataLen = static_cast(headerLength + (itemLen * meta->item_count) + meta->data_count); + uint32_t encodeDataLen = headerLength + (itemLen * meta->item_count) + meta->data_count; std::string s(encodeDataLen, '\0'); char *encodeData = &s[0]; ret = memcpy_s(encodeData, encodeDataLen, meta, headerLength); -- Gitee From 6d0d892406823b4008660005adec39b1468f7b79 Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Fri, 22 Aug 2025 11:13:53 +0000 Subject: [PATCH 3/5] update camera/metadata/src/metadata_utils.cpp. Signed-off-by: wanghongenaf --- camera/metadata/src/metadata_utils.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/camera/metadata/src/metadata_utils.cpp b/camera/metadata/src/metadata_utils.cpp index 69471a95..6a7a4c23 100644 --- a/camera/metadata/src/metadata_utils.cpp +++ b/camera/metadata/src/metadata_utils.cpp @@ -24,6 +24,10 @@ if (cond) { \ return {}; \ } +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + namespace OHOS::Camera { void MetadataUtils::WriteMetadataDataToVec(const camera_metadata_item_t &entry, std::vector& cameraAbility) { @@ -417,6 +421,8 @@ std::string MetadataUtils::EncodeToString(std::shared_ptr metada } common_metadata_header_t *meta = metadata->get(); + METADATA_CHECK_ERROR_RETURN_RET_LOG( + UINT32_MAX / itemLen <= meta->item_count, {}, "UINT32_MAX / itemLen <= meta->item_count"); uint32_t encodeDataLen = headerLength + (itemLen * meta->item_count) + meta->data_count; std::string s(encodeDataLen, '\0'); char *encodeData = &s[0]; @@ -433,8 +439,12 @@ std::string MetadataUtils::EncodeToString(std::shared_ptr metada METADATA_CHECK_ERROR_RETURN_RET_LOG( ret != EOK, {}, "MetadataUtils::EncodeToString Failed to copy memory for item fixed fields"); encodeData += itemFixedLen; + METADATA_CHECK_ERROR_RETURN_RET_LOG( + encodeDataLen <= itemFixedLen, {}, "encodeDataLen <= itemFixedLen"); encodeDataLen -= itemFixedLen; - int32_t dataLen = itemLen - itemFixedLen; + METADATA_CHECK_ERROR_RETURN_RET_LOG( + itemLen < itemFixedLen, {}, "itemLen <= itemFixedLen"); + uint32_t dataLen = itemLen - itemFixedLen; METADATA_CHECK_ERROR_RETURN_RET_LOG( item == nullptr, {}, "MetadataUtils::EncodeToString Failed, item is nullptr"); ret = memcpy_s(encodeData, encodeDataLen, &(item->data), dataLen); -- Gitee From 2f7888746bf0915f84c39daa8d6ffe7e57894a66 Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Fri, 22 Aug 2025 11:15:55 +0000 Subject: [PATCH 4/5] update camera/metadata/src/metadata_utils.cpp. Signed-off-by: wanghongenaf --- camera/metadata/src/metadata_utils.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/camera/metadata/src/metadata_utils.cpp b/camera/metadata/src/metadata_utils.cpp index 6a7a4c23..b77e24d8 100644 --- a/camera/metadata/src/metadata_utils.cpp +++ b/camera/metadata/src/metadata_utils.cpp @@ -406,8 +406,6 @@ bool MetadataUtils::WriteMetadata(const camera_metadata_item_t &item, MessagePar return bRet; } -static int32_t - std::string MetadataUtils::EncodeToString(std::shared_ptr metadata) { int32_t ret; -- Gitee From 8355527cb262c6abcdb0624dbce277d41dd7ef61 Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Fri, 22 Aug 2025 11:40:54 +0000 Subject: [PATCH 5/5] update camera/metadata/src/metadata_utils.cpp. Signed-off-by: wanghongenaf --- camera/metadata/src/metadata_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camera/metadata/src/metadata_utils.cpp b/camera/metadata/src/metadata_utils.cpp index b77e24d8..87ab37a0 100644 --- a/camera/metadata/src/metadata_utils.cpp +++ b/camera/metadata/src/metadata_utils.cpp @@ -420,7 +420,7 @@ std::string MetadataUtils::EncodeToString(std::shared_ptr metada common_metadata_header_t *meta = metadata->get(); METADATA_CHECK_ERROR_RETURN_RET_LOG( - UINT32_MAX / itemLen <= meta->item_count, {}, "UINT32_MAX / itemLen <= meta->item_count"); + UINT32_MAX / itemLen <= meta->item_count, {}, "UINT32_MAX / itemLen <= meta->item_count"); uint32_t encodeDataLen = headerLength + (itemLen * meta->item_count) + meta->data_count; std::string s(encodeDataLen, '\0'); char *encodeData = &s[0]; -- Gitee