diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..599873284b856381f21036cdb4546d66575e078a --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/multimedia/image_framework/ide/image_decode_config.gni") + +ohos_fuzztest("ImageFwkExifWebp2FuzzTest") { + module_out_path = "multimedia_image/image_framework" + fuzz_config_file = "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer" + + include_dirs = [ + "./include", + "$image_subsystem/interfaces/innerkits/include", + "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/common/include", + ] + + sources = [ + "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/common/src/common_fuzztest_function.cpp", + "src/image_fwk_exif_webp_fuzzer.cpp", + ] + + deps = [ + "$image_subsystem/interfaces/innerkits:image_native", + "$image_subsystem/plugins/common/libs/image/libextplugin:extplugin", + ] + + external_deps = [ + "c_utils:utils", + "graphic_2d:color_manager", + "hilog:libhilog", + "libexif:libexif", + ] +} diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer/project.xml b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..f4306c35ff225e97a89b504d9e8f976ccec470b8 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 2000 + + 300 + + 4096 + + diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer/src/image_fwk_exif_webp_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer/src/image_fwk_exif_webp_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3688e5d63cac29e3b4a5b79a0d89942d08ceeadc --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp2_fuzzer/src/image_fwk_exif_webp_fuzzer.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include "image_fwk_exif_webp_fuzzer.h" +#define private public + +#include +#include +#include +#include +#include +#include "securec.h" + +#include "common_fuzztest_function.h" +#include "metadata_accessor_factory.h" +#include "dng_exif_metadata_accessor.h" +#include "heif_exif_metadata_accessor.h" +#include "jpeg_exif_metadata_accessor.h" +#include "png_exif_metadata_accessor.h" +#include "webp_exif_metadata_accessor.h" +#include "file_metadata_stream.h" +#include "image_log.h" + +#undef LOG_DOMAIN +#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE + +#undef LOG_TAG +#define LOG_TAG "IMAGE_FWK_EXIF_WEBP_FUZZ" + +namespace OHOS { +namespace Media { +using namespace std; +FuzzedDataProvider* FDP; + +static const std::string WEBP_EXIF_PATH = "/data/local/tmp/test_exif.webp"; +constexpr uint32_t OPT_SIZE = 40; +constexpr uint32_t MEMORYMODE_MODULO = 2; + +void MetadataAccessorFuncTest001(std::shared_ptr& metadataAccessor) +{ + if (metadataAccessor == nullptr) { + return; + } + metadataAccessor->Read(); + auto exifMetadata = metadataAccessor->Get(); + if (exifMetadata == nullptr) { + return; + } + uint32_t index = FDP->ConsumeIntegral() % KEY_VALUE_MAPS.size(); + auto key = KEY_VALUE_MAPS[index].first; + for (const auto &v : KEY_VALUE_MAPS[index].second) { + exifMetadata->SetValue(key, v); + std::string value; + exifMetadata->GetValue(key, value); + } + metadataAccessor->Write(); + metadataAccessor->Set(exifMetadata); + DataBuf inputBuf; + metadataAccessor->ReadBlob(inputBuf); + metadataAccessor->WriteBlob(inputBuf); +} + +void WebpAccessorTest001(const uint8_t *data, size_t size) +{ + IMAGE_LOGI("%{public}s IN", __func__); + int fd = open(WEBP_EXIF_PATH.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (write(fd, data, size) != (ssize_t)size) { + close(fd); + return; + } + std::shared_ptr stream = std::make_shared(fd); + if (stream == nullptr || !stream->Open(OpenMode::ReadWrite)) { + IMAGE_LOGE("Failed to open the stream with file descriptor: %{public}d", fd); + close(fd); + return; + } + uint32_t error = 0; + EncodedFormat type = MetadataAccessorFactory::GetImageType(stream, error); + if (type != EncodedFormat::WEBP) { + IMAGE_LOGI("%{public}s type is not WEBP", __func__); + close(fd); + return; + } + std::shared_ptr metadataAccessor1 = MetadataAccessorFactory::Create(fd); + MetadataAccessorFuncTest001(metadataAccessor1); + close(fd); + + BufferMetadataStream::MemoryMode mode = static_cast(FDP->ConsumeIntegral() % MEMORYMODE_MODULO); + std::shared_ptr metadataAccessor2 = MetadataAccessorFactory::Create(const_cast(data), + size, mode); + if (metadataAccessor2 == nullptr) { + IMAGE_LOGE("Create metadata accessor failed"); + return; + } + auto webpMetadataAccessor = reinterpret_cast(metadataAccessor2.get()); + webpMetadataAccessor->Read(); + webpMetadataAccessor->Write(); + Vp8xAndExifInfo exifFlag = Vp8xAndExifInfo::UNKNOWN; + webpMetadataAccessor->CheckChunkVp8x(exifFlag); + webpMetadataAccessor->GetImageWidthAndHeight(); + std::string strChunkId = "000"; + DataBuf chunkData = {}; + webpMetadataAccessor->GetWidthAndHeightFormChunk(strChunkId, chunkData); + IMAGE_LOGI("%{public}s SUCCESS", __func__); +} + +void DataBufTest(const uint8_t *data, size_t size) +{ + if (size == 0) { + return; + } + DataBuf dataBuf(data, size); + dataBuf.ReadUInt8(0); + dataBuf.Resize(size); + dataBuf.WriteUInt8(0, 0); + dataBuf.Reset(); +} +} // namespace Media +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (size < OHOS::Media::OPT_SIZE) { + return -1; + } + FuzzedDataProvider fdp(data + size - OHOS::Media::OPT_SIZE, OHOS::Media::OPT_SIZE); + OHOS::Media::FDP = &fdp; + WriteDataToFile(data, size - OHOS::Media::OPT_SIZE, OHOS::Media::WEBP_EXIF_PATH); + uint8_t action = fdp.ConsumeIntegral() % 2; + switch(action){ + case 0: + OHOS::Media::DataBufTest(data, size); + break; + case 1: + OHOS::Media::WebpAccessorTest001(data, size); + break; + } + return 0; +} \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e46ce5e3da0acd33462a7a93ed769c3e10a9f11c --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/multimedia/image_framework/ide/image_decode_config.gni") + +ohos_fuzztest("ImageFwkExifWebpFuzzTest") { + module_out_path = "multimedia_image/image_framework" + fuzz_config_file = "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer" + + include_dirs = [ + "./include", + "$image_subsystem/interfaces/innerkits/include", + "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/common/include", + ] + + sources = [ + "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/common/src/common_fuzztest_function.cpp", + "src/image_fwk_exif_webp_fuzzer.cpp", + ] + + deps = [ + "$image_subsystem/interfaces/innerkits:image_native", + "$image_subsystem/plugins/common/libs/image/libextplugin:extplugin", + ] + + external_deps = [ + "c_utils:utils", + "graphic_2d:color_manager", + "hilog:libhilog", + "libexif:libexif", + ] +} diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer/project.xml b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6fe7b2a8c8e203fb61757312de28700e0bfc4ae3 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 2000 + + 300 + + 4096 + + diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer/src/image_fwk_exif_webp_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer/src/image_fwk_exif_webp_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..083d7c5f902221366f023ff9f651af948368390e --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkexifwebp_fuzzer/src/image_fwk_exif_webp_fuzzer.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "image_fwk_exif_webp_fuzzer.h" +#define private public + +#include +#include +#include +#include +#include +#include "securec.h" + +#include "common_fuzztest_function.h" +#include "metadata_accessor_factory.h" +#include "dng_exif_metadata_accessor.h" +#include "heif_exif_metadata_accessor.h" +#include "jpeg_exif_metadata_accessor.h" +#include "png_exif_metadata_accessor.h" +#include "webp_exif_metadata_accessor.h" +#include "file_metadata_stream.h" +#include "image_log.h" + +#undef LOG_DOMAIN +#define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE + +#undef LOG_TAG +#define LOG_TAG "IMAGE_FWK_EXIF_WEBP_FUZZ" + +namespace OHOS { +namespace Media { +using namespace std; + +static const std::string WEBP_EXIF_PATH = "/data/local/tmp/test_exif.webp"; + +void MetadataAccessorFuncTest001(std::shared_ptr& metadataAccessor) +{ + if (metadataAccessor == nullptr) { + return; + } + metadataAccessor->Read(); + auto exifMetadata = metadataAccessor->Get(); + if (exifMetadata == nullptr) { + return; + } + std::string key = "ImageWidth"; + exifMetadata->SetValue(key, "500"); + std::string value; + exifMetadata->GetValue(key, value); + metadataAccessor->Write(); + metadataAccessor->Set(exifMetadata); + DataBuf inputBuf; + metadataAccessor->ReadBlob(inputBuf); + metadataAccessor->WriteBlob(inputBuf); +} + +void WebpAccessorTest001(const uint8_t *data, size_t size) +{ + IMAGE_LOGI("%{public}s IN", __func__); + int fd = open(WEBP_EXIF_PATH.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (write(fd, data, size) != (ssize_t)size) { + close(fd); + return; + } + std::shared_ptr stream = std::make_shared(fd); + if (stream == nullptr || !stream->Open(OpenMode::ReadWrite)) { + IMAGE_LOGE("Failed to open the stream with file descriptor: %{public}d", fd); + close(fd); + return; + } + uint32_t error = 0; + EncodedFormat type = MetadataAccessorFactory::GetImageType(stream, error); + if (type != EncodedFormat::WEBP) { + IMAGE_LOGI("%{public}s type is not WEBP", __func__); + close(fd); + return; + } + std::shared_ptr metadataAccessor1 = MetadataAccessorFactory::Create(fd); + MetadataAccessorFuncTest001(metadataAccessor1); + close(fd); + + BufferMetadataStream::MemoryMode mode = BufferMetadataStream::MemoryMode::Dynamic; + std::shared_ptr metadataAccessor2 = MetadataAccessorFactory::Create(const_cast(data), + size, mode); + if (metadataAccessor2 == nullptr) { + IMAGE_LOGE("Create metadata accessor failed"); + return; + } + auto webpMetadataAccessor = reinterpret_cast(metadataAccessor2.get()); + webpMetadataAccessor->Read(); + webpMetadataAccessor->Write(); + Vp8xAndExifInfo exifFlag = Vp8xAndExifInfo::UNKNOWN; + webpMetadataAccessor->CheckChunkVp8x(exifFlag); + webpMetadataAccessor->GetImageWidthAndHeight(); + std::string strChunkId = "000"; + DataBuf chunkData = {}; + webpMetadataAccessor->GetWidthAndHeightFormChunk(strChunkId, chunkData); + IMAGE_LOGI("%{public}s SUCCESS", __func__); +} + +void DataBufTest(const uint8_t *data, size_t size) +{ + if (size == 0) { + return; + } + DataBuf dataBuf(data, size); + dataBuf.ReadUInt8(0); + dataBuf.Resize(size); + dataBuf.WriteUInt8(0, 0); + dataBuf.Reset(); +} +} // namespace Media +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::Media::DataBufTest(data, size); + OHOS::Media::WebpAccessorTest001(data, size); + return 0; +} \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource2_fuzzer/src/image_fwk_image_source2_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource2_fuzzer/src/image_fwk_image_source2_fuzzer.cpp index d4e2506d64c8e22e5fdd378f6814a76e04824a80..922f7a3f5bd87b495884886997dc740c7921c2c4 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource2_fuzzer/src/image_fwk_image_source2_fuzzer.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource2_fuzzer/src/image_fwk_image_source2_fuzzer.cpp @@ -36,9 +36,6 @@ static const std::string GIF_FORMAT = "image/gif"; static const std::string PNG_FORMAT = "image/png"; static const std::string IMAGE_ENCODE_DEST = "/data/local/tmp/test_out.dat"; constexpr uint32_t SOURCEOPTIONS_MIMETYPE_MODULO = 3; -static constexpr uint32_t ALLOCATORTYPE_MODULO = 5; -static constexpr uint32_t DYNAMICRANGE_MODULO = 4; -static constexpr uint32_t QUALITY_MODULO = 101; namespace OHOS { namespace Media { @@ -51,7 +48,6 @@ void ImageSourceFuncTest002(std::unique_ptr &imageSource, DecodeOpt ImageInfo imageInfo; imageSource->ImageConverChange(cropRect, imageInfo, imageInfo); imageSource->CreatePixelMapForYUV(errCode); - imageSource->CreatePixelMapForASTC(errCode, opts); imageSource->CreatePixelMapList(opts, errCode); imageSource->GetDelayTime(errCode); imageSource->GetDisposalType(errCode); @@ -64,9 +60,6 @@ void ImageSourceFuncTest002(std::unique_ptr &imageSource, DecodeOpt auto incrementalRecordIter = imageSource->incDecodingMap_.find(&pixelMap); imageSource->AddIncrementalContext(pixelMap, incrementalRecordIter); imageSource->GetImageInfoFromExif(0, imageInfo); - int32_t type = FDP->ConsumeIntegral() % ALLOCATORTYPE_MODULO; - imageSource->IsSupportAllocatorType(opts, type); - IMAGE_LOGI("%{public}s SUCCESS", __func__); } @@ -88,7 +81,6 @@ void ImageSourceFuncTest001(std::unique_ptr &imageSource) imageSource->GetImagePropertyCommon(0, key, value); imageSource->GetImagePropertyInt(0, key, valueInt); imageSource->GetImagePropertyString(0, key, value); - imageSource->GetImagePropertyStringBySync(0, key, value); imageSource->GetSourceInfo(errCode); imageSource->RegisterListener(nullptr); imageSource->UnRegisterListener(nullptr); @@ -102,7 +94,6 @@ void ImageSourceFuncTest001(std::unique_ptr &imageSource) imageSource->DecodeSourceInfo(true); imageSource->CreateDecoder(errCode); DecodeOptions opts; - SetFdpDecodeOptions(FDP, opts); DecodeOptions procOpts; PixelMap pixelMap; imageSource->CopyOptionsToProcOpts(opts, procOpts, pixelMap); @@ -122,7 +113,6 @@ void CreateIncrementalPixelMapByDataFuzz(const uint8_t *data, size_t size) auto imageSource = Media::ImageSource::CreateIncrementalImageSource(incOpts, errorCode); if (imageSource != nullptr) { DecodeOptions decodeOpts; - SetFdpDecodeOptions(FDP, decodeOpts); std::unique_ptr incPixelMap = imageSource->CreateIncrementalPixelMap(0, decodeOpts, errorCode); uint32_t res = imageSource->UpdateData(data, size, true); @@ -144,7 +134,6 @@ void CreateImageSourceByPathFuzz(const std::string &pathName) return; } ImageSourceFuncTest001(imageSource); - imageSource->RemoveImageProperties(0, {"ImageWidth", "ImageHeight"}, pathName); Media::DecodeOptions dopts; SetFdpDecodeOptions(FDP, dopts); imageSource->CreatePixelMap(dopts, errorCode); @@ -171,7 +160,6 @@ void CreateImageSourceByFDEXFuzz(const std::string &pathName) if (imagesource != nullptr) { imagesource->CreatePixelMap(dopts, errorCode); } - imagesource->RemoveImageProperties(0, {"ImageWidth", "ImageHeight"}, fd); close(fd); } @@ -235,6 +223,8 @@ void ImageSourceFuzzTest(const uint8_t *data, size_t size) } SourceOptions opts; uint32_t errorCode = 0; + std::string mimeType[] = {"image/jpeg", "image/heic", "image/heif"}; + opts.formatHint = mimeType[FDP->ConsumeIntegral() % SOURCEOPTIONS_MIMETYPE_MODULO]; std::shared_ptr imageSource = ImageSource::CreateImageSource(data, size, opts, errorCode); if (imageSource == nullptr) { return; @@ -249,35 +239,6 @@ void ImageSourceFuzzTest(const uint8_t *data, size_t size) bool isAddUV = false; std::vector buffer; imageSource->ConvertYUV420ToRGBA(buffer.data(), size, isSupportOdd, isAddUV, errorCode); - DecodeOptions decOps; - SetFdpDecodeOptions(FDP, decOps); - int32_t allocatorType = FDP->ConsumeIntegral(); - imageSource->IsSupportAllocatorType(decOps, allocatorType); - imageSource->IsSvgUseDma(decOps); - imageSource->GetImageId(); - int filterType = FDP->ConsumeIntegral(); - std::vector> ranges; - imageSource->GetFilterArea(filterType, ranges); - imageSource->GetMemoryUsagePreference(); - MemoryUsagePreference memoryUsagePreference = - static_cast(FDP->ConsumeIntegral() % 2); - imageSource->SetMemoryUsagePreference(memoryUsagePreference); - imageSource->GetNinePatchInfo(); - std::set keys = {"DateTimeOriginal", "ExposureTime", "SceneType", "GIFLoopCount"}; - imageSource->RemoveImageProperties(0, keys, 0); - std::string value = ""; - imageSource->GetImagePropertyStringBySync(0, key, value); - uint32_t frameCount = imageSource->GetFrameCount(errorCode); - std::string metadataValue = ""; - for (uint32_t index = 0; index < frameCount; index++) { - auto picture = imageSource->CreatePictureAtIndex(index, errorCode); - if (picture == nullptr) { - return; - } - auto gifMetadata = picture->GetMetadata(MetadataType::GIF); - gifMetadata->GetValue(GIF_METADATA_KEY_DELAY_TIME, metadataValue); - gifMetadata->GetValue(GIF_METADATA_KEY_DISPOSAL_TYPE, metadataValue); - } } static std::string GetProperty(std::unique_ptr &imageSource, const std::string &prop) @@ -316,9 +277,6 @@ void EncodePictureTest(std::shared_ptr picture, const std::string &form ImagePacker pack; PackOption packOption; packOption.format = format; - packOption.quality = FDP->ConsumeIntegral() % DYNAMICRANGE_MODULO; - packOption.desiredDynamicRange = static_cast(FDP->ConsumeIntegral() % QUALITY_MODULO); - packOption.needsPackProperties = FDP->ConsumeBool(); if (pack.StartPacking(outputPath, packOption) != SUCCESS) { IMAGE_LOGE("%{public}s StartPacking failed.", __func__); return; @@ -344,9 +302,6 @@ void EncodePixelMapTest(std::shared_ptr pixelmap, const std::string &f ImagePacker pack; PackOption packOption; packOption.format = format; - packOption.quality = FDP->ConsumeIntegral() % DYNAMICRANGE_MODULO; - packOption.desiredDynamicRange = static_cast(FDP->ConsumeIntegral() % QUALITY_MODULO); - packOption.needsPackProperties = FDP->ConsumeBool(); if (pack.StartPacking(outputPath, packOption) != SUCCESS) { IMAGE_LOGE("%{public}s StartPacking failed.", __func__); return; @@ -385,7 +340,7 @@ bool CreatePixelMapUseArgbByRandomImageSource(const uint8_t *data, size_t size) EncodePixelMapTest(pixelMap, formats[index], IMAGE_ENCODE_DEST); } ImageInfo info; - if (pixelMap != nullptr) { + if (pixelMap == nullptr) { pixelMap->GetImageInfo(info); } std::shared_ptr auxPicture = @@ -404,8 +359,6 @@ bool CreatePixelMapUseArgbByRandomImageSource(const uint8_t *data, size_t size) EncodePictureTest(picture, HEIF_FORMAT, IMAGE_ENCODE_DEST); } } - auto gifIndex = FDP->ConsumeIntegral() % SOURCEOPTIONS_MIMETYPE_MODULO; - picture = imageSource->CreatePictureAtIndex(gifIndex, errorCode); return true; } diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/BUILD.gn index ede7d1bf513c655715df5a0040c77b812fcd4c72..e821e5697c5fc00b6aeaad71450f4f7a8e167b28 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkimagesource_fuzzer/BUILD.gn @@ -21,7 +21,7 @@ ohos_fuzztest("ImageFwkImageSourceFuzzTest") { include_dirs = [ "./include", - "$image_subsystem/interfaces/innerkits/include", + "$image_subsystem/frameworks/innerkitsimpl/utils/include", "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/common/include", ] 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 3546696b1dd879a560cfd8aeb734c4e7cca65663..3e13a80103949026d6ab44f228414b6e5f380dc2 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 @@ -376,7 +376,7 @@ bool CreatePixelMapUseArgbByRandomImageSource(const uint8_t *data, size_t size) dopts.allocatorType = imageSource->ConvertAutoAllocatorType(dopts); pixelMap = imageSource->CreatePixelMap(0, dopts, errorCode); ImageInfo info; - if (pixelMap != nullptr) { + if (pixelMap == nullptr) { pixelMap->GetImageInfo(info); } std::shared_ptr auxPicture = AuxiliaryPicture::Create(pixelMap, diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagepixelYuv_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/imagepixelYuv_fuzzer/BUILD.gn index 2137bd9eb565a44201723b625b002719289db6ac..c9b7039a8849846b597a0dbee63d701ab269182b 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imagepixelYuv_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/imagepixelYuv_fuzzer/BUILD.gn @@ -27,7 +27,7 @@ ohos_fuzztest("ImagePixelYuvFuzzTest") { deps = [ "$image_subsystem/frameworks/innerkitsimpl/utils:image_utils", "$image_subsystem/interfaces/innerkits:image_native", - ] + ] external_deps = [ "c_utils:utils", "hilog:libhilog", diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagepixelmapsetalpha_fuzzer/src/pixelmap_setalpha.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagepixelmapsetalpha_fuzzer/src/pixelmap_setalpha.cpp index 352a38f16e8fa2b9fb41c6e405bd11a60360c55a..e706cfe363f516f51c494c686bfc64d76a523d51 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imagepixelmapsetalpha_fuzzer/src/pixelmap_setalpha.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/imagepixelmapsetalpha_fuzzer/src/pixelmap_setalpha.cpp @@ -35,6 +35,7 @@ constexpr uint32_t SETALPHAMINWIDTH = 50; constexpr uint32_t SETALPHAMINHEIGHT = 50; constexpr uint32_t NUM_15 = 15; constexpr uint32_t NUM_12 = 12; +constexpr uint32_t NUM_4 = 4; namespace OHOS { namespace Media { @@ -98,7 +99,7 @@ std::unique_ptr GetPixelMapFromOpts(const Media::Initialization */ std::unique_ptr GetPixelMapFromOptsAndRandomData(const Media::InitializationOptions &opts) { - uint32_t size = opts.size.width * opts.size.height; + uint32_t size = opts.size.width * opts.size.height * NUM_4; std::unique_ptr buffer = std::make_unique(size); for (uint32_t i = 0; i < size; i++) { buffer[i] = GetData(); diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagepngplugin_fuzzer/src/image_png_plugin_fuzz.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagepngplugin_fuzzer/src/image_png_plugin_fuzz.cpp index 17796c2e0d6d281ddb49f4d48b37c0abda251023..9836a1deb5caa19b22fb117fc38bd952629ef4ae 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imagepngplugin_fuzzer/src/image_png_plugin_fuzz.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/imagepngplugin_fuzzer/src/image_png_plugin_fuzz.cpp @@ -98,9 +98,9 @@ void PngDecoderFuncTest001(const std::string& filename) pngDecoder = nullptr; return; } - DoPrivateFun(pngDecoder); Size size; pngDecoder->GetImageSize(0, size); + DoPrivateFun(pngDecoder); ProgDecodeContext progContext; pngDecoder->PromoteIncrementalDecode(0, progContext); pngDecoder->SetSource(*(pngDecoder->inputStreamPtr_));