From 8f0bc66cf5d85e20d405a47243bf991735dbb1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=85=89=E8=80=80?= Date: Wed, 10 Sep 2025 16:32:16 +0800 Subject: [PATCH] test0901-002 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 | 10 ++++++++-- .../src/texture_encode/image_compressor.cpp | 9 +++++++-- .../libs/image/libpngplugin/src/png_decoder.cpp | 4 ++++ plugins/manager/src/framework/plugin_mgr.cpp | 16 ++++++++++++++-- 5 files changed, 38 insertions(+), 11 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..a7f399d4e 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 d939c9a92..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 @@ -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 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/framework/plugin_mgr.cpp b/plugins/manager/src/framework/plugin_mgr.cpp index ce8705ecf..1d7f993da 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; -- Gitee