From 557a4118ae61b137fb1672f96b4b0673bf848e7d Mon Sep 17 00:00:00 2001 From: AiChaosN Date: Tue, 10 Jun 2025 09:38:32 +0800 Subject: [PATCH] uewReBuild Change-Id: I8d3633e8a97df4a9dbeac8f7aad13d9eb5eceaa2 Signed-off-by: AiChaosN --- .../innerkitsimpl/codec/src/image_source.cpp | 92 +++++++++++++++---- .../imagefwkimagesource_fuzzer/BUILD.gn | 1 + .../src/image_fwk_image_source_fuzzer.cpp | 7 +- .../image_source_test/image_source_test.cpp | 7 +- .../kits/js/common/image_source_napi.cpp | 19 ++-- interfaces/innerkits/include/image_source.h | 4 +- 6 files changed, 100 insertions(+), 30 deletions(-) diff --git a/frameworks/innerkitsimpl/codec/src/image_source.cpp b/frameworks/innerkitsimpl/codec/src/image_source.cpp index 2e61e542f..9026a3f32 100644 --- a/frameworks/innerkitsimpl/codec/src/image_source.cpp +++ b/frameworks/innerkitsimpl/codec/src/image_source.cpp @@ -1855,25 +1855,51 @@ uint32_t ImageSource::CreateExifMetadata(uint8_t *buffer, const uint32_t size, b return SUCCESS; } -uint32_t ImageSource::GetImagePropertyCommon(uint32_t index, const std::string &key, std::string &value) +uint32_t ImageSource::IsGIFLoopCount(uint32_t index, const std::string &key, std::string &value, bool &needRet) +{ + uint32_t ret = 0; + if (IMAGE_GIFLOOPCOUNT_TYPE.compare(key) == ZERO) { + IMAGE_LOGD("GetImagePropertyString special key: %{public}s", key.c_str()); + (void)GetFrameCount(ret); + if (ret != SUCCESS || mainDecoder_ == nullptr) { + IMAGE_LOGE("[ImageSource]GetFrameCount get frame sum error."); + needRet = true; + return ret; + } else { + ret = mainDecoder_->GetImagePropertyString(index, key, value); + if (ret != SUCCESS) { + IMAGE_LOGE("[ImageSource]GetLoopCount get loop count issue. errorCode=%{public}u", ret); + needRet = true; + return ret; + } + } + needRet = true; + return ret; + } + return ret; +} + +uint32_t ImageSource::GetImagePropertyCommon(uint32_t index, const std::string &key, std::string &value, bool &needRet) { if (isExifReadFailed_ && exifMetadata_ == nullptr) { + needRet = true; return exifReadStatus_; } uint32_t ret = CreatExifMetadataByImageSource(); if (ret != SUCCESS) { if (key.substr(0, KEY_SIZE) == "Hw") { value = DEFAULT_EXIF_VALUE; + needRet = true; return SUCCESS; } IMAGE_LOGD("Failed to create Exif metadata " "when attempting to get property."); isExifReadFailed_ = true; exifReadStatus_ = ret; + needRet = true; return ret; } - - return exifMetadata_->GetValue(key, value); + return ret; } uint32_t ImageSource::GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value) @@ -1890,7 +1916,12 @@ uint32_t ImageSource::GetImagePropertyInt(uint32_t index, const std::string &key return ret; } std::string strValue; - uint32_t ret = GetImagePropertyCommon(index, key, strValue); + bool needRet = false; + uint32_t ret = GetImagePropertyCommon(index, key, strValue, needRet); + if (needRet) { + return ret; + } + ret = exifMetadata_->GetValue(key, strValue); if (key == "Orientation") { if (ORIENTATION_INT_MAP.count(strValue) == 0) { IMAGE_LOGD("ORIENTATION_INT_MAP not find %{public}s", strValue.c_str()); @@ -1914,25 +1945,50 @@ uint32_t ImageSource::GetImagePropertyString(uint32_t index, const std::string & return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT; } uint32_t ret = SUCCESS; - if (IMAGE_GIFLOOPCOUNT_TYPE.compare(key) == ZERO) { - IMAGE_LOGD("GetImagePropertyString special key: %{public}s", key.c_str()); - (void)GetFrameCount(ret); - if (ret != SUCCESS || mainDecoder_ == nullptr) { - IMAGE_LOGE("[ImageSource]GetFrameCount get frame sum error."); - return ret; - } else { - ret = mainDecoder_->GetImagePropertyString(index, key, value); - if (ret != SUCCESS) { - IMAGE_LOGE("[ImageSource]GetLoopCount get loop count issue. errorCode=%{public}u", ret); - return ret; - } - } + bool needRet = false; + ret = IsGIFLoopCount(index, key, value, needRet); + if (needRet) { + return ret; + } + + std::unique_lock guard(decodingMutex_); + std::unique_lock guardFile(fileMutex_); + + ret = GetImagePropertyCommon(index, key, value, needRet); + if (needRet) { + return ret; + } + + ret = exifMetadata_->GetValue(key, value); + return ret; +} + +uint32_t ImageSource::GetImagePropertyStringBySync(uint32_t index, const std::string &key, std::string &value) +{ + if (key.empty()) { + return Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT; + } + + uint32_t ret = SUCCESS; + bool needRet = false; + ret = IsGIFLoopCount(index, key, value, needRet); + if (needRet) { return ret; } std::unique_lock guard(decodingMutex_); std::unique_lock guardFile(fileMutex_); - return GetImagePropertyCommon(index, key, value); + + ret = GetImagePropertyCommon(index, key, value, needRet); + if (needRet) { + return ret; + } + + ret = exifMetadata_->GetValue(key, value); + if (ret != SUCCESS) { + return ERR_IMAGE_PROPERTY_NOT_EXIST; + } + return SUCCESS; } const SourceInfo &ImageSource::GetSourceInfo(uint32_t &errorCode) diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/BUILD.gn index ede7d1bf5..0c60e0408 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/BUILD.gn @@ -39,5 +39,6 @@ ohos_fuzztest("ImageFwkImageSourceFuzzTest") { "c_utils:utils", "graphic_2d:color_manager", "hilog:libhilog", + "libexif:libexif", ] } diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/src/image_fwk_image_source_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/src/image_fwk_image_source_fuzzer.cpp index dad694664..10e2605f5 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/src/image_fwk_image_source_fuzzer.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/src/image_fwk_image_source_fuzzer.cpp @@ -26,6 +26,7 @@ #include "image_log.h" #include "image_packer.h" #include "image_source.h" +#include "exif_metadata.h" #include "image_utils.h" #include "media_errors.h" @@ -82,7 +83,11 @@ void ImageSourceFuncTest001(std::unique_ptr& imageSource) imageSource->ModifyImageProperty(0, key, value, ""); imageSource->ModifyImageProperty(0, key, value, 0); imageSource->ModifyImageProperty(0, key, value, nullptr, 0); - imageSource->GetImagePropertyCommon(0, key, value); + bool needRet = false; + imageSource->GetImagePropertyCommon(0, key, value, needRet); + if (!needRet) { + imageSource->exifMetadata_->GetValue(key, value); + } imageSource->GetImagePropertyInt(0, key, valueInt); imageSource->GetImagePropertyString(0, key, value); imageSource->GetSourceInfo(errCode); diff --git a/frameworks/innerkitsimpl/test/unittest/image_source_test/image_source_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_source_test/image_source_test.cpp index f85c4665e..dd3ab3fcf 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_source_test/image_source_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_source_test/image_source_test.cpp @@ -2859,8 +2859,11 @@ HWTEST_F(ImageSourceTest, GetImagePropertyCommonTest001, TestSize.Level1) imageSource->isExifReadFailed_ = false; imageSource->exifMetadata_.reset(); std::string key{"Hw"}, value; - - errorCode = imageSource->GetImagePropertyCommon(0, key, value); + bool needRet = false; + errorCode = imageSource->GetImagePropertyCommon(0, key, value, needRet); + if (!needRet) { + errorCode = imageSource->exifMetadata_->GetValue(key, value); + } ASSERT_EQ(value, std::string{"default_exif_value"}); ASSERT_EQ(errorCode, SUCCESS); GTEST_LOG_(INFO) << "ImageSourceTest: GetImagePropertyCommonTest001 end"; diff --git a/frameworks/kits/js/common/image_source_napi.cpp b/frameworks/kits/js/common/image_source_napi.cpp index 10edebea5..d9cc4a163 100644 --- a/frameworks/kits/js/common/image_source_napi.cpp +++ b/frameworks/kits/js/common/image_source_napi.cpp @@ -2536,23 +2536,26 @@ napi_value ImageSourceNapi::GetImagePropertySync(napi_env env, napi_callback_inf napi_value result = nullptr; napi_get_undefined(env, &result); - uint32_t ret = imageSourceNapi->nativeImgSrc->GetImagePropertyString(NUM_0, key, value); + uint32_t ret = imageSourceNapi->nativeImgSrc->GetImagePropertyStringBySync(NUM_0, key, value); if (ret == SUCCESS) { napi_create_string_utf8(env, value.c_str(), value.length(), &result); return result; } + if (ret == Media::ERR_IMAGE_PROPERTY_NOT_EXIST) { + IMAGE_LOGE("%{public}s: Unsupported metadata, errorCode=%{public}u", __func__, ret); + return ImageNapiUtils::ThrowExceptionError(env, IMAGE_SOURCE_UNSUPPORTED_METADATA, "Unsupported metadata"); + } if (ret == Media::ERR_IMAGE_SOURCE_DATA) { - IMAGE_LOGE("%{public}s: Bad source", __func__); - return ImageNapiUtils::ThrowExceptionError(env, IMAGE_BAD_SOURCE, "Bad source"); + IMAGE_LOGE("%{public}s: Unsupported MIME type, errorCode=%{public}u", __func__, ret); + return ImageNapiUtils::ThrowExceptionError(env, IMAGE_SOURCE_UNSUPPORTED_MIMETYPE, "Unsupported MIME type"); } if (ret == Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT) { - IMAGE_LOGE("%{public}s: Unsupported MIME type", __func__); - return ImageNapiUtils::ThrowExceptionError(env, IMAGE_SOURCE_UNSUPPORTED_MIMETYPE, "Unsupported MIME type"); + IMAGE_LOGE("%{public}s: Bad source, errorCode=%{public}u", __func__, ret); + return ImageNapiUtils::ThrowExceptionError(env, IMAGE_BAD_SOURCE, "Bad source"); } - IMAGE_LOGE("%{public}s: Unsupported metadata", __func__); - return ImageNapiUtils::ThrowExceptionError(env, IMAGE_SOURCE_UNSUPPORTED_METADATA, "Unsupported metadata"); } - return ImageNapiUtils::ThrowExceptionError(env, IMAGE_SOURCE_UNSUPPORTED_METADATA, "Unsupported metadata"); + IMAGE_LOGE("%{public}s: Bad source", __func__); + return ImageNapiUtils::ThrowExceptionError(env, IMAGE_BAD_SOURCE, "Bad source"); } static void UpdateDataExecute(napi_env env, void *data) diff --git a/interfaces/innerkits/include/image_source.h b/interfaces/innerkits/include/image_source.h index d52d5161f..60969fb05 100644 --- a/interfaces/innerkits/include/image_source.h +++ b/interfaces/innerkits/include/image_source.h @@ -219,6 +219,7 @@ public: NATIVEEXPORT bool IsIncrementalSource(); NATIVEEXPORT uint32_t GetImagePropertyInt(uint32_t index, const std::string &key, int32_t &value); NATIVEEXPORT uint32_t GetImagePropertyString(uint32_t index, const std::string &key, std::string &value); + NATIVEEXPORT uint32_t GetImagePropertyStringBySync(uint32_t index, const std::string &key, std::string &value); NATIVEEXPORT uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value, const std::string &path); NATIVEEXPORT uint32_t ModifyImageProperty(uint32_t index, const std::string &key, const std::string &value, @@ -296,7 +297,8 @@ private: IncrementalDecodingContext &recordContext); void SetIncrementalSource(const bool isIncrementalSource); bool IsStreamCompleted(); - uint32_t GetImagePropertyCommon(uint32_t index, const std::string &key, std::string &value); + uint32_t IsGIFLoopCount(uint32_t index, const std::string &key, std::string &value, bool &needRet); + uint32_t GetImagePropertyCommon(uint32_t index, const std::string &key, std::string &value, bool &needRet); FinalOutputStep GetFinalOutputStep(const DecodeOptions &opts, PixelMap &pixelMap, bool hasNinePatch); bool HasDensityChange(const DecodeOptions &opts, ImageInfo &srcImageInfo, bool hasNinePatch); bool ImageSizeChange(int32_t width, int32_t height, int32_t desiredWidth, int32_t desiredHeight); -- Gitee