diff --git a/frameworks/innerkitsimpl/common/src/pixel_map.cpp b/frameworks/innerkitsimpl/common/src/pixel_map.cpp index f070744b3beb388b2debec9e0009b0085b536a28..210fc93f729e9900eabb156c0cb2f08898bb5f28 100644 --- a/frameworks/innerkitsimpl/common/src/pixel_map.cpp +++ b/frameworks/innerkitsimpl/common/src/pixel_map.cpp @@ -91,6 +91,9 @@ extern "C" { #undef LOG_TAG #define LOG_TAG "PixelMap" +#define BUF_NAME_LEN 255 +#define PREFIX_NAME_LEN 255 + namespace OHOS { namespace Media { using namespace std; @@ -514,10 +517,10 @@ uint32_t PixelMap::SetMemoryName(const std::string &pixelMapName) if (GetFd() == nullptr) { return ERR_MEMORY_NOT_SUPPORT; } - AllocatorType allocatorType = GetAllocatorType(); - - if (pixelMapName.empty() || pixelMapName.size() > DMA_BUF_NAME_LEN - 1) { + if (pixelMapName.empty() || + (pixelMapName.size() > BUF_NAME_LEN && allocatorType == AllocatorType::DMA_ALLOC) || + (pixelMapName.size() > BUF_NAME_LEN - PREFIX_NAME_LEN && allocatorType == AllocatorType::SHARE_MEM_ALLOC)) { return COMMON_ERR_INVALID_PARAMETER; } diff --git a/frameworks/innerkitsimpl/test/unittest/pixel_map_test/pixel_map_test.cpp b/frameworks/innerkitsimpl/test/unittest/pixel_map_test/pixel_map_test.cpp index eceb87de3f81fadf7aa32a2d18c62318d0d93af1..8b24c760dda888c4273efd6ee770fc73dea973f8 100644 --- a/frameworks/innerkitsimpl/test/unittest/pixel_map_test/pixel_map_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/pixel_map_test/pixel_map_test.cpp @@ -2613,7 +2613,7 @@ HWTEST_F(PixelMapTest, SetMemoryNameTest001, TestSize.Level3) EXPECT_TRUE(ret != ERR_MEMORY_NOT_SUPPORT); EXPECT_TRUE(ret == SUCCESS); - std::string longName(50, '1'); + std::string longName(257, '1'); ret = pixelMap->SetMemoryName(longName); EXPECT_TRUE(ret != ERR_MEMORY_NOT_SUPPORT); EXPECT_TRUE(ret == COMMON_ERR_INVALID_PARAMETER);