From 1be57f570fb31b398de0b84a7ce4f09d4f054c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=85=89=E8=80=80?= Date: Tue, 9 Sep 2025 18:57:37 +0800 Subject: [PATCH 1/3] fix_codecheck_20250909 update001 Signed-off-by heguangyao MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 何光耀 --- .../innerkitsimpl/codec/src/image_source.cpp | 10 +++++----- .../innerkitsimpl/utils/src/image_utils.cpp | 11 +++++++++-- .../src/texture_encode/image_compressor.cpp | 11 +++++++++-- .../image/libpngplugin/src/png_decoder.cpp | 4 ++++ plugins/manager/src/common/platform_adp.cpp | 16 +++++++++++++++- plugins/manager/src/framework/plugin_mgr.cpp | 18 ++++++++++++++++-- 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/frameworks/innerkitsimpl/codec/src/image_source.cpp b/frameworks/innerkitsimpl/codec/src/image_source.cpp index 68f077254..667e5b077 100644 --- a/frameworks/innerkitsimpl/codec/src/image_source.cpp +++ b/frameworks/innerkitsimpl/codec/src/image_source.cpp @@ -685,7 +685,7 @@ static inline bool IsDensityChange(int32_t srcDensity, int32_t wantDensity) static inline int32_t GetScalePropByDensity(int32_t prop, int32_t srcDensity, int32_t wantDensity) { bool cond = srcDensity != 0; - int32_t ret = (prop * wantDensity + (srcDensity >> 1)) / srcDensity; + int32_t ret = (prop * wantDensity + (srcDensity / 2)) / srcDensity; CHECK_ERROR_RETURN_RET(cond, ret); return prop; } @@ -4337,10 +4337,10 @@ bool ImageSource::ApplyGainMap(ImageHdrType hdrType, DecodeContext& baseCtx, Dec void ImageSource::SetVividMetaColor(HdrMetadata& metadata, CM_ColorSpaceType base, CM_ColorSpaceType gainmap, CM_ColorSpaceType hdr) { - metadata.extendMeta.baseColorMeta.baseColorPrimary = base & 0xFF; - metadata.extendMeta.gainmapColorMeta.enhanceDataColorPrimary = gainmap & 0xFF; - metadata.extendMeta.gainmapColorMeta.combineColorPrimary = gainmap & 0xFF; - metadata.extendMeta.gainmapColorMeta.alternateColorPrimary = hdr & 0xFF; + metadata.extendMeta.baseColorMeta.baseColorPrimary = static_cast(base) & 0xFF; + metadata.extendMeta.gainmapColorMeta.enhanceDataColorPrimary = static_cast(gainmap) & 0xFF; + metadata.extendMeta.gainmapColorMeta.combineColorPrimary = static_cast(gainmap) & 0xFF; + metadata.extendMeta.gainmapColorMeta.alternateColorPrimary = static_cast(hdr) & 0xFF; } static CM_HDR_Metadata_Type GetHdrMediaType(HdrMetadata& metadata) diff --git a/frameworks/innerkitsimpl/utils/src/image_utils.cpp b/frameworks/innerkitsimpl/utils/src/image_utils.cpp index ba67e2ffe..4b01e224d 100644 --- a/frameworks/innerkitsimpl/utils/src/image_utils.cpp +++ b/frameworks/innerkitsimpl/utils/src/image_utils.cpp @@ -968,9 +968,16 @@ bool ImageUtils::SetInitializationOptionAllocatorType(InitializationOptions &opt uint32_t ImageUtils::SaveDataToFile(const std::string& fileName, const char* data, const size_t& totalSize) { - std::ofstream outFile(fileName, std::ofstream::out); + char* realLoadPath = realpath(fileName.c_str(), nullptr); + if (realLoadPath == nullptr) { + IMAGE_LOGE("realpath check failed"); + return IMAGE_RESULT_SAVE_DATA_TO_FILE_FAILED; + } + std::string loadPath(realLoadPath); + free(realLoadPath); + std::ofstream outFile(loadPath, std::ofstream::out); if (!outFile.is_open()) { - IMAGE_LOGI("ImageUtils::SaveDataToFile write error, path=%{public}s", fileName.c_str()); + IMAGE_LOGI("ImageUtils::SaveDataToFile write error, path=%{public}s", loadPath.c_str()); return IMAGE_RESULT_SAVE_DATA_TO_FILE_FAILED; } if (data == nullptr) { diff --git a/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp b/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp index d939c9a92..c39c2e614 100644 --- a/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp +++ b/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp @@ -1400,9 +1400,16 @@ static CL_ASTC_STATUS SaveClBin(cl_program program, const std::string &clBinPath free(programBinaries); return CL_ASTC_ENC_FAILED; } - FILE *fp = fopen(clBinPath.c_str(), "wb"); + char* realLoadPath = realpath(clBinPath.c_str(), nullptr); + if (realLoadPath == nullptr) { + IMAGE_LOGE("realpath check failed"); + return CL_ASTC_ENC_FAILED; + } + std::string loadPath(realLoadPath); + free(realLoadPath); + FILE *fp = fopen(loadPath.c_str(), "wb"); if (fp == nullptr) { - IMAGE_LOGE("astc create file: %{public}s failed!", clBinPath.c_str()); + IMAGE_LOGE("astc create file: %{public}s failed!", loadPath.c_str()); free(programBinaries); return CL_ASTC_ENC_FAILED; } diff --git a/plugins/common/libs/image/libpngplugin/src/png_decoder.cpp b/plugins/common/libs/image/libpngplugin/src/png_decoder.cpp index d9bc65275..8bc16ba64 100644 --- a/plugins/common/libs/image/libpngplugin/src/png_decoder.cpp +++ b/plugins/common/libs/image/libpngplugin/src/png_decoder.cpp @@ -735,6 +735,7 @@ uint32_t PngDecoder::ReadIncrementalHead(InputDataStream *stream, PngImageInfo & } stream->Seek(pos); // set the exception handle + CHECK_ERROR_RETURN_RET_LOG(pngStructPtr_ == nullptr, ERR_IMAGE_DECODE_HEAD_ABNORMAL, "pngStructPtr_ is nullptr"); if (png_jmpbuf(pngStructPtr_) == nullptr) { return ERR_IMAGE_DECODE_HEAD_ABNORMAL; } @@ -928,6 +929,7 @@ uint32_t PngDecoder::IncrementalReadRows(InputDataStream *stream) return ERR_IMAGE_INVALID_PARAMETER; } // set the exception handle + CHECK_ERROR_RETURN_RET_LOG(pngStructPtr_ == nullptr, ERR_IMAGE_DECODE_ABNORMAL, "pngStructPtr_ is nullptr"); if (png_jmpbuf(pngStructPtr_) == nullptr) { return ERR_IMAGE_DECODE_ABNORMAL; } @@ -1074,6 +1076,7 @@ uint32_t PngDecoder::ConfigInfo(const PixelDecodeOptions &opts) } // get the libpng interface exception. + CHECK_ERROR_RETURN_RET_LOG(pngStructPtr_ == nullptr, ERR_IMAGE_DATA_ABNORMAL, "pngStructPtr_ is nullptr"); if (png_jmpbuf(pngStructPtr_) == nullptr) { return ERR_IMAGE_DATA_ABNORMAL; } @@ -1092,6 +1095,7 @@ uint32_t PngDecoder::DoOneTimeDecode(DecodeContext &context) IMAGE_LOGE("normal decode the image source incomplete."); return ERR_IMAGE_SOURCE_DATA_INCOMPLETE; } + CHECK_ERROR_RETURN_RET_LOG(pngStructPtr_ == nullptr, ERR_IMAGE_DECODE_ABNORMAL, "pngStructPtr_ is nullptr"); if (png_jmpbuf(pngStructPtr_) == nullptr) { return ERR_IMAGE_DECODE_ABNORMAL; } diff --git a/plugins/manager/src/common/platform_adp.cpp b/plugins/manager/src/common/platform_adp.cpp index 3f3d0ecc5..c10ae1f20 100644 --- a/plugins/manager/src/common/platform_adp.cpp +++ b/plugins/manager/src/common/platform_adp.cpp @@ -22,6 +22,8 @@ #include "string" #include "plugin_errors.h" #include "type_traits" +#include +#include #undef LOG_DOMAIN #define LOG_DOMAIN LOG_TAG_DOMAIN_ID_PLUGIN @@ -54,7 +56,19 @@ FARPROC PlatformAdp::AdpGetSymAddress(HMODULE handle, const string &symbol) #else void *PlatformAdp::LoadLibrary(const std::string &packageName) { - return dlopen(packageName.c_str(), RTLD_LAZY); + char* realLoadPath = realpath(fileName.c_str(), nullptr); + if (realLoadPath == nullptr) { + IMAGE_LOGE("realpath check failed"); + return NULL; + } + std::string loadPath(realLoadPath); + free(realLoadPath); + struct stat fileStat; + if (stat(loadPath, &fileStat) != 0) { + IMAGE_LOGE("unable to get file info"); + return NULL; + } + return dlopen(loadPath.c_str(), RTLD_LAZY); } void PlatformAdp::FreeLibrary(void *handle) diff --git a/plugins/manager/src/framework/plugin_mgr.cpp b/plugins/manager/src/framework/plugin_mgr.cpp index ce8705ecf..3bd0d38bb 100644 --- a/plugins/manager/src/framework/plugin_mgr.cpp +++ b/plugins/manager/src/framework/plugin_mgr.cpp @@ -132,7 +132,14 @@ bool PluginMgr::CheckPluginMetaFile(const string &candidateFile, string &library return false; } - ifstream metadata(candidateFile); + char* realLoadPath = realpath(candidateFile.c_str(), nullptr); + if (realLoadPath == nullptr) { + IMAGE_LOGE("realpath check failed"); + return false; + } + std::string loadPath(realLoadPath); + free(realLoadPath); + ifstream metadata(loadPath); if (!metadata.is_open()) { IMAGE_LOGE("failed to open metadata file."); return false; @@ -186,7 +193,14 @@ uint32_t PluginMgr::RegisterPlugin(const string &metadataPath, string &&libraryP return ERR_GENERAL; } - ifstream metadata(metadataPath); + char* realLoadPath = realpath(metadataPath.c_str(), nullptr); + if (realLoadPath == nullptr) { + IMAGE_LOGE("realpath check failed"); + return ERR_GENERAL; + } + std::string loadPath(realLoadPath); + free(realLoadPath); + ifstream metadata(loadPath); if (!metadata.is_open()) { IMAGE_LOGE("failed to open metadata file."); return ERR_GENERAL; -- Gitee From 034a37bf239289e8e644790b3f9a6bfc8dc18b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=85=89=E8=80=80?= Date: Tue, 9 Sep 2025 19:37:18 +0800 Subject: [PATCH 2/3] fix_codecheck_20250909 update002 Signed-off-by heguangyao MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 何光耀 --- .../innerkitsimpl/utils/src/image_utils.cpp | 10 ++++------ .../src/texture_encode/image_compressor.cpp | 10 ++++------ plugins/manager/src/common/platform_adp.cpp | 14 ++++++-------- plugins/manager/src/framework/plugin_mgr.cpp | 16 ++++++---------- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/frameworks/innerkitsimpl/utils/src/image_utils.cpp b/frameworks/innerkitsimpl/utils/src/image_utils.cpp index 4b01e224d..8bac89261 100644 --- a/frameworks/innerkitsimpl/utils/src/image_utils.cpp +++ b/frameworks/innerkitsimpl/utils/src/image_utils.cpp @@ -968,16 +968,14 @@ bool ImageUtils::SetInitializationOptionAllocatorType(InitializationOptions &opt uint32_t ImageUtils::SaveDataToFile(const std::string& fileName, const char* data, const size_t& totalSize) { - char* realLoadPath = realpath(fileName.c_str(), nullptr); - if (realLoadPath == nullptr) { + char realLoadPath[PATH_MAX] = { 0 }; + if (realpath(fileName.c_str(), realLoadPath) == nullptr) { IMAGE_LOGE("realpath check failed"); return IMAGE_RESULT_SAVE_DATA_TO_FILE_FAILED; } - std::string loadPath(realLoadPath); - free(realLoadPath); - std::ofstream outFile(loadPath, std::ofstream::out); + std::ofstream outFile(realLoadPath, std::ofstream::out); if (!outFile.is_open()) { - IMAGE_LOGI("ImageUtils::SaveDataToFile write error, path=%{public}s", loadPath.c_str()); + IMAGE_LOGI("ImageUtils::SaveDataToFile write error, path=%{public}s", realLoadPath.c_str()); return IMAGE_RESULT_SAVE_DATA_TO_FILE_FAILED; } if (data == nullptr) { diff --git a/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp b/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp index c39c2e614..d088cc153 100644 --- a/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp +++ b/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp @@ -1400,16 +1400,14 @@ static CL_ASTC_STATUS SaveClBin(cl_program program, const std::string &clBinPath free(programBinaries); return CL_ASTC_ENC_FAILED; } - char* realLoadPath = realpath(clBinPath.c_str(), nullptr); - if (realLoadPath == nullptr) { + char realLoadPath[PATH_MAX] = { 0 }; + if (realpath(clBinPath.c_str(), realLoadPath) == nullptr) { IMAGE_LOGE("realpath check failed"); return CL_ASTC_ENC_FAILED; } - std::string loadPath(realLoadPath); - free(realLoadPath); - FILE *fp = fopen(loadPath.c_str(), "wb"); + FILE *fp = fopen(realLoadPath.c_str(), "wb"); if (fp == nullptr) { - IMAGE_LOGE("astc create file: %{public}s failed!", loadPath.c_str()); + IMAGE_LOGE("astc create file: %{public}s failed!", realLoadPath.c_str()); free(programBinaries); return CL_ASTC_ENC_FAILED; } diff --git a/plugins/manager/src/common/platform_adp.cpp b/plugins/manager/src/common/platform_adp.cpp index c10ae1f20..415ac4ae6 100644 --- a/plugins/manager/src/common/platform_adp.cpp +++ b/plugins/manager/src/common/platform_adp.cpp @@ -56,19 +56,17 @@ FARPROC PlatformAdp::AdpGetSymAddress(HMODULE handle, const string &symbol) #else void *PlatformAdp::LoadLibrary(const std::string &packageName) { - char* realLoadPath = realpath(fileName.c_str(), nullptr); - if (realLoadPath == nullptr) { + char realLoadPath[PATH_MAX] = { 0 }; + if (realpath(packageName.c_str(), realLoadPath) == nullptr) { IMAGE_LOGE("realpath check failed"); - return NULL; + return nullptr; } - std::string loadPath(realLoadPath); - free(realLoadPath); struct stat fileStat; - if (stat(loadPath, &fileStat) != 0) { + if (stat(realLoadPath, &fileStat) != 0) { IMAGE_LOGE("unable to get file info"); - return NULL; + return nullptr; } - return dlopen(loadPath.c_str(), RTLD_LAZY); + return dlopen(realLoadPath.c_str(), RTLD_LAZY); } void PlatformAdp::FreeLibrary(void *handle) diff --git a/plugins/manager/src/framework/plugin_mgr.cpp b/plugins/manager/src/framework/plugin_mgr.cpp index 3bd0d38bb..2b2fc43de 100644 --- a/plugins/manager/src/framework/plugin_mgr.cpp +++ b/plugins/manager/src/framework/plugin_mgr.cpp @@ -132,14 +132,12 @@ bool PluginMgr::CheckPluginMetaFile(const string &candidateFile, string &library return false; } - char* realLoadPath = realpath(candidateFile.c_str(), nullptr); - if (realLoadPath == nullptr) { + char realLoadPath[PATH_MAX] = { 0 }; + if (realpath(candidateFile.c_str(), realLoadPath) == nullptr) { IMAGE_LOGE("realpath check failed"); return false; } - std::string loadPath(realLoadPath); - free(realLoadPath); - ifstream metadata(loadPath); + ifstream metadata(realLoadPath); if (!metadata.is_open()) { IMAGE_LOGE("failed to open metadata file."); return false; @@ -193,14 +191,12 @@ uint32_t PluginMgr::RegisterPlugin(const string &metadataPath, string &&libraryP return ERR_GENERAL; } - char* realLoadPath = realpath(metadataPath.c_str(), nullptr); - if (realLoadPath == nullptr) { + char realLoadPath[PATH_MAX] = { 0 }; + if (realpath(metadataPath.c_str(), realLoadPath) == nullptr) { IMAGE_LOGE("realpath check failed"); return ERR_GENERAL; } - std::string loadPath(realLoadPath); - free(realLoadPath); - ifstream metadata(loadPath); + ifstream metadata(realLoadPath); if (!metadata.is_open()) { IMAGE_LOGE("failed to open metadata file."); return ERR_GENERAL; -- Gitee From 55cfa19c3be1aed06a258af2e496117e552000ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=85=89=E8=80=80?= Date: Tue, 9 Sep 2025 20:00:14 +0800 Subject: [PATCH 3/3] fix_codecheck_20250909 update003 Signed-off-by heguangyao MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 何光耀 --- frameworks/innerkitsimpl/utils/src/image_utils.cpp | 5 +++-- .../libextplugin/src/texture_encode/image_compressor.cpp | 4 ++-- plugins/manager/src/common/platform_adp.cpp | 2 +- plugins/manager/src/framework/plugin_mgr.cpp | 6 ++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/frameworks/innerkitsimpl/utils/src/image_utils.cpp b/frameworks/innerkitsimpl/utils/src/image_utils.cpp index 8bac89261..a7f399d4e 100644 --- a/frameworks/innerkitsimpl/utils/src/image_utils.cpp +++ b/frameworks/innerkitsimpl/utils/src/image_utils.cpp @@ -973,9 +973,10 @@ uint32_t ImageUtils::SaveDataToFile(const std::string& fileName, const char* dat IMAGE_LOGE("realpath check failed"); return IMAGE_RESULT_SAVE_DATA_TO_FILE_FAILED; } - std::ofstream outFile(realLoadPath, std::ofstream::out); + std::string loadPath(realLoadPath); + std::ofstream outFile(loadPath, std::ofstream::out); if (!outFile.is_open()) { - IMAGE_LOGI("ImageUtils::SaveDataToFile write error, path=%{public}s", realLoadPath.c_str()); + IMAGE_LOGI("ImageUtils::SaveDataToFile write error, path=%{public}s", loadPath.c_str()); return IMAGE_RESULT_SAVE_DATA_TO_FILE_FAILED; } if (data == nullptr) { diff --git a/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp b/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp index d088cc153..23adbc8a0 100644 --- a/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp +++ b/plugins/common/libs/image/libextplugin/src/texture_encode/image_compressor.cpp @@ -1405,9 +1405,9 @@ static CL_ASTC_STATUS SaveClBin(cl_program program, const std::string &clBinPath IMAGE_LOGE("realpath check failed"); return CL_ASTC_ENC_FAILED; } - FILE *fp = fopen(realLoadPath.c_str(), "wb"); + FILE *fp = fopen(realLoadPath, "wb"); if (fp == nullptr) { - IMAGE_LOGE("astc create file: %{public}s failed!", realLoadPath.c_str()); + IMAGE_LOGE("astc create file: %{public}s failed!", realLoadPath); free(programBinaries); return CL_ASTC_ENC_FAILED; } diff --git a/plugins/manager/src/common/platform_adp.cpp b/plugins/manager/src/common/platform_adp.cpp index 415ac4ae6..268a1140f 100644 --- a/plugins/manager/src/common/platform_adp.cpp +++ b/plugins/manager/src/common/platform_adp.cpp @@ -66,7 +66,7 @@ void *PlatformAdp::LoadLibrary(const std::string &packageName) IMAGE_LOGE("unable to get file info"); return nullptr; } - return dlopen(realLoadPath.c_str(), RTLD_LAZY); + return dlopen(realLoadPath, RTLD_LAZY); } void PlatformAdp::FreeLibrary(void *handle) diff --git a/plugins/manager/src/framework/plugin_mgr.cpp b/plugins/manager/src/framework/plugin_mgr.cpp index 2b2fc43de..1d7f993da 100644 --- a/plugins/manager/src/framework/plugin_mgr.cpp +++ b/plugins/manager/src/framework/plugin_mgr.cpp @@ -137,7 +137,8 @@ bool PluginMgr::CheckPluginMetaFile(const string &candidateFile, string &library IMAGE_LOGE("realpath check failed"); return false; } - ifstream metadata(realLoadPath); + std::string loadPath(realLoadPath); + ifstream metadata(loadPath); if (!metadata.is_open()) { IMAGE_LOGE("failed to open metadata file."); return false; @@ -196,7 +197,8 @@ uint32_t PluginMgr::RegisterPlugin(const string &metadataPath, string &&libraryP IMAGE_LOGE("realpath check failed"); return ERR_GENERAL; } - ifstream metadata(realLoadPath); + std::string loadPath(realLoadPath); + ifstream metadata(loadPath); if (!metadata.is_open()) { IMAGE_LOGE("failed to open metadata file."); return ERR_GENERAL; -- Gitee