diff --git a/frameworks/innerkitsimpl/codec/src/image_source.cpp b/frameworks/innerkitsimpl/codec/src/image_source.cpp index 68f07725470861c7f62984386b3528c7ebafbc0c..667e5b077c6e9150867325661422739bd35370fc 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 ba67e2ffebaf915510fe6cfaef03a422aa0a07f9..a7f399d4ecf0d57381f101092ec831720f6684f0 100644 --- a/frameworks/innerkitsimpl/utils/src/image_utils.cpp +++ b/frameworks/innerkitsimpl/utils/src/image_utils.cpp @@ -968,9 +968,15 @@ 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[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); + 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 d939c9a922cbe482874c6a2590d5246ee95d5cda..23adbc8a0c99051f68823ef9cfc65e5c6908ff73 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,14 @@ 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[PATH_MAX] = { 0 }; + if (realpath(clBinPath.c_str(), realLoadPath) == nullptr) { + IMAGE_LOGE("realpath check failed"); + return CL_ASTC_ENC_FAILED; + } + FILE *fp = fopen(realLoadPath, "wb"); if (fp == nullptr) { - IMAGE_LOGE("astc create file: %{public}s failed!", clBinPath.c_str()); + IMAGE_LOGE("astc create file: %{public}s failed!", realLoadPath); 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 d9bc652754df9537d297cdb8a37b3b5be0d1f9fa..8bc16ba64d1742d511d9f2682a26f2898d925714 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 3f3d0ecc5142094943fd3cbc5a8cd6824e43b85b..268a1140f300c4b94e0639c90e4d33c7773b1a94 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,17 @@ 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[PATH_MAX] = { 0 }; + if (realpath(packageName.c_str(), realLoadPath) == nullptr) { + IMAGE_LOGE("realpath check failed"); + return nullptr; + } + struct stat fileStat; + if (stat(realLoadPath, &fileStat) != 0) { + IMAGE_LOGE("unable to get file info"); + return nullptr; + } + 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 ce8705ecf29a030e22bcef59fc3ca63b3677902d..1d7f993da4870c9b79f94534368d59a34fbdf541 100644 --- a/plugins/manager/src/framework/plugin_mgr.cpp +++ b/plugins/manager/src/framework/plugin_mgr.cpp @@ -132,7 +132,13 @@ bool PluginMgr::CheckPluginMetaFile(const string &candidateFile, string &library return false; } - ifstream metadata(candidateFile); + char realLoadPath[PATH_MAX] = { 0 }; + if (realpath(candidateFile.c_str(), realLoadPath) == nullptr) { + IMAGE_LOGE("realpath check failed"); + return false; + } + std::string loadPath(realLoadPath); + ifstream metadata(loadPath); if (!metadata.is_open()) { IMAGE_LOGE("failed to open metadata file."); return false; @@ -186,7 +192,13 @@ uint32_t PluginMgr::RegisterPlugin(const string &metadataPath, string &&libraryP return ERR_GENERAL; } - ifstream metadata(metadataPath); + char realLoadPath[PATH_MAX] = { 0 }; + if (realpath(metadataPath.c_str(), realLoadPath) == nullptr) { + IMAGE_LOGE("realpath check failed"); + return ERR_GENERAL; + } + std::string loadPath(realLoadPath); + ifstream metadata(loadPath); if (!metadata.is_open()) { IMAGE_LOGE("failed to open metadata file."); return ERR_GENERAL;