diff --git a/frameworks/innerkitsimpl/test/fuzztest/common/include/common_fuzztest_function.h b/frameworks/innerkitsimpl/test/fuzztest/common/include/common_fuzztest_function.h index 080dfb59c6bc7127e10e57e26d8b8b06d0e93c40..c0a613a1e0e6eb1c034a81780109fc6caaa723c7 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/common/include/common_fuzztest_function.h +++ b/frameworks/innerkitsimpl/test/fuzztest/common/include/common_fuzztest_function.h @@ -15,6 +15,7 @@ #ifndef FRAMEWORKS_INNERKITSIMPL_TEST_FUZZTEST_COMMON_FUZZTEST_FUNCTION_H #define FRAMEWORKS_INNERKITSIMPL_TEST_FUZZTEST_COMMON_FUZZTEST_FUNCTION_H +#include #include #include #include diff --git a/frameworks/innerkitsimpl/test/fuzztest/imageaccessor_fuzzer/src/image_accessor_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imageaccessor_fuzzer/src/image_accessor_fuzzer.cpp index b1b36c489f3d3cd292d2b07a5e9e82467acd8287..5ef1dabbf2f35de1a879b3b7643e88d566b01e01 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imageaccessor_fuzzer/src/image_accessor_fuzzer.cpp +++ b/frameworks/innerkitsimpl/test/fuzztest/imageaccessor_fuzzer/src/image_accessor_fuzzer.cpp @@ -43,11 +43,245 @@ namespace OHOS { namespace Media { using namespace std; -static const std::string JPEG_EXIF_PATH = "/data/local/tmp/test_exif.jpg"; -static const std::string PNG_EXIF_PATH = "/data/local/tmp/test_exif.png"; -static const std::string WEBP_EXIF_PATH = "/data/local/tmp/test.webp"; -static const std::string HEIF_EXIF_PATH = "/data/local/tmp/test_exif.heic"; -static const std::string DNG_EXIF_PATH = "/data/local/tmp/test.dng"; +void AccessMetadata(std::shared_ptr exifMetadata, const std::string& key, const std::string &value) +{ + if (exifMetadata == nullptr) { + IMAGE_LOGI("%{public}s failed, exifMetadata is null", __func__); + return; + } + exifMetadata->SetValue(key, value); + std::string res = ""; + exifMetadata->GetValue(key, res); + exifMetadata->RemoveEntry(key); +} + +void MetadataFuncTest001(std::shared_ptr exifMetadata) +{ + IMAGE_LOGI("%{public}s IN", __func__); + if (exifMetadata == nullptr) { + IMAGE_LOGI("%{public}s failed, exifMetadata is null", __func__); + return; + } + AccessMetadata(exifMetadata, "BitsPerSample", "9, 7, 8"); + AccessMetadata(exifMetadata, "Orientation", "Top-right"); + AccessMetadata(exifMetadata, "ImageLength", "1000"); + AccessMetadata(exifMetadata, "ImageWidth", "500"); + AccessMetadata(exifMetadata, "GPSLatitude", "39, 54, 20"); + AccessMetadata(exifMetadata, "GPSLongitude", "120, 52, 26"); + AccessMetadata(exifMetadata, "GPSLatitudeRef", "N"); + AccessMetadata(exifMetadata, "GPSLongitudeRef", "E"); + AccessMetadata(exifMetadata, "DateTimeOriginal", "2024:01:25 05:51:34"); + AccessMetadata(exifMetadata, "ExposureTime", "1/34 sec."); + AccessMetadata(exifMetadata, "SceneType", "Directly photographed"); + AccessMetadata(exifMetadata, "ISOSpeedRatings", "160"); + AccessMetadata(exifMetadata, "FNumber", "f/3.0"); + AccessMetadata(exifMetadata, "DateTime", ""); + AccessMetadata(exifMetadata, "GPSTimeStamp", "11:37:58.00"); + AccessMetadata(exifMetadata, "GPSDateStamp", "2025:01:11"); + AccessMetadata(exifMetadata, "ImageDescription", "_cuva"); + AccessMetadata(exifMetadata, "Make", ""); + AccessMetadata(exifMetadata, "Model", "TNY-AL00"); + AccessMetadata(exifMetadata, "SensitivityType", "Standard output sensitivity (SOS) and ISO speed"); + AccessMetadata(exifMetadata, "StandardOutputSensitivity", "5"); + AccessMetadata(exifMetadata, "RecommendedExposureIndex", "241"); + AccessMetadata(exifMetadata, "ApertureValue", "4.00 EV (f/4.0)"); + AccessMetadata(exifMetadata, "ExposureBiasValue", "23.00 EV"); + AccessMetadata(exifMetadata, "MeteringMode", "Pattern"); + AccessMetadata(exifMetadata, "LightSource", "Fluorescent"); + AccessMetadata(exifMetadata, "Flash", "Strobe return light not detected"); + AccessMetadata(exifMetadata, "FocalLength", "31.0 mm"); + AccessMetadata(exifMetadata, "UserComment", "comm"); + AccessMetadata(exifMetadata, "PixelXDimension", "1000"); + AccessMetadata(exifMetadata, "PixelYDimension", "2000"); + AccessMetadata(exifMetadata, "WhiteBalance", "Manual white balance"); + AccessMetadata(exifMetadata, "FocalLengthIn35mmFilm", "26"); + AccessMetadata(exifMetadata, "JPEGProc", "252"); + AccessMetadata(exifMetadata, "MakerNote", "HwMnoteCaptureMode:123"); + IMAGE_LOGI("%{public}s SUCCESS", __func__); +} + +void MetadataFuncTest002(std::shared_ptr exifMetadata) +{ + IMAGE_LOGI("%{public}s IN", __func__); + if (exifMetadata == nullptr) { + IMAGE_LOGI("%{public}s failed, exifMetadata is null", __func__); + return; + } + AccessMetadata(exifMetadata, "MaxApertureValue", "0.08 EV (f/1.0)"); + AccessMetadata(exifMetadata, "Artist", "Joseph.Xu"); + AccessMetadata(exifMetadata, "NewSubfileType", "1"); + AccessMetadata(exifMetadata, "OECF", "1 bytes undefined data"); + AccessMetadata(exifMetadata, "PlanarConfiguration", "Chunky format"); + AccessMetadata(exifMetadata, "PrimaryChromaticities", "124"); + AccessMetadata(exifMetadata, "ReferenceBlackWhite", "221"); + AccessMetadata(exifMetadata, "ResolutionUnit", "Inch"); + AccessMetadata(exifMetadata, "SamplesPerPixel", "23"); + AccessMetadata(exifMetadata, "Compression", "JPEG compression"); + AccessMetadata(exifMetadata, "Software", "MNA-AL00 4.0.0.120(C00E116R3P7)"); + AccessMetadata(exifMetadata, "Copyright", "xxxxxx (Photographer) - [None] (Editor)"); + AccessMetadata(exifMetadata, "SpectralSensitivity", "sensitivity"); + AccessMetadata(exifMetadata, "DNGVersion", "0x01, 0x01, 0x02, 0x03"); + AccessMetadata(exifMetadata, "SubjectDistance", ""); + AccessMetadata(exifMetadata, "DefaultCropSize", "12, 1"); + AccessMetadata(exifMetadata, "SubjectLocation", "3"); + AccessMetadata(exifMetadata, "TransferFunction", "2"); + AccessMetadata(exifMetadata, "WhitePoint", "124.2"); + AccessMetadata(exifMetadata, "XResolution", "72"); + AccessMetadata(exifMetadata, "YCbCrCoefficients", "0.299, 0.587, 0.114"); + AccessMetadata(exifMetadata, "YCbCrPositioning", "Centered"); + AccessMetadata(exifMetadata, "YCbCrSubSampling", "3, 2"); + AccessMetadata(exifMetadata, "YResolution", "72"); + AccessMetadata(exifMetadata, "Gamma", "1.5"); + AccessMetadata(exifMetadata, "ISOSpeed", "200"); + AccessMetadata(exifMetadata, "ISOSpeedLatitudeyyy", "3"); + AccessMetadata(exifMetadata, "ISOSpeedLatitudezzz", "3"); + AccessMetadata(exifMetadata, "ImageUniqueID", "FXIC012"); + AccessMetadata(exifMetadata, "JPEGInterchangeFormat", ""); + AccessMetadata(exifMetadata, "JPEGInterchangeFormatLength", ""); + IMAGE_LOGI("%{public}s SUCCESS", __func__); +} + +void MetadataFuncTest003(std::shared_ptr exifMetadata) +{ + IMAGE_LOGI("%{public}s IN", __func__); + if (exifMetadata == nullptr) { + IMAGE_LOGI("%{public}s failed, exifMetadata is null", __func__); + return; + } + AccessMetadata(exifMetadata, "GPSAltitude", "0.00"); + AccessMetadata(exifMetadata, "GPSAltitudeRef", "Sea level reference"); + AccessMetadata(exifMetadata, "GPSAreaInformation", "23...15...57"); + AccessMetadata(exifMetadata, "GPSDOP", "182"); + AccessMetadata(exifMetadata, "GPSDestBearing", "2.6"); + AccessMetadata(exifMetadata, "GPSDestBearingRef", "T"); + AccessMetadata(exifMetadata, "GPSDestDistance", "10"); + AccessMetadata(exifMetadata, "GPSDestDistanceRef", "N"); + AccessMetadata(exifMetadata, "GPSDestLatitude", "33, 22, 11"); + AccessMetadata(exifMetadata, "GPSDestLatitudeRef", "N"); + AccessMetadata(exifMetadata, "GPSDestLongitude", "33, 22, 11"); + AccessMetadata(exifMetadata, "GPSDestLongitudeRef", "E"); + AccessMetadata(exifMetadata, "GPSDifferential", "1"); + AccessMetadata(exifMetadata, "GPSImgDirection", "2.23214"); + AccessMetadata(exifMetadata, "GPSImgDirectionRef", "M"); + AccessMetadata(exifMetadata, "GPSMapDatum", "xxxx"); + AccessMetadata(exifMetadata, "GPSMeasureMode", "2"); + AccessMetadata(exifMetadata, "GPSProcessingMethod", "CELLID"); + AccessMetadata(exifMetadata, "GPSSatellites", "xxx"); + AccessMetadata(exifMetadata, "GPSSpeed", "150"); + AccessMetadata(exifMetadata, "GPSSpeedRef", "K"); + AccessMetadata(exifMetadata, "GPSStatus", "V"); + AccessMetadata(exifMetadata, "GPSTrack", "56"); + AccessMetadata(exifMetadata, "GPSTrackRef", "T"); + AccessMetadata(exifMetadata, "GPSVersionID", "2.2.0.0"); + AccessMetadata(exifMetadata, "GPSHPositioningError", " 3"); + AccessMetadata(exifMetadata, "LensMake", "xxx"); + AccessMetadata(exifMetadata, "LensModel", "xxx"); + AccessMetadata(exifMetadata, "LensSerialNumber", "xxx"); + AccessMetadata(exifMetadata, "LensSpecification", " 1, 1.5, 1, 2"); + AccessMetadata(exifMetadata, "MakerNote", "HwMnoteCaptureMode:123"); + AccessMetadata(exifMetadata, "GainControl", "Normal"); + AccessMetadata(exifMetadata, "OffsetTime", "xx"); + AccessMetadata(exifMetadata, "OffsetTimeDigitized", "xx"); + AccessMetadata(exifMetadata, "OffsetTimeOriginal", "xx"); + AccessMetadata(exifMetadata, "PhotometricInterpretation", ""); + AccessMetadata(exifMetadata, "RelatedSoundFile", "/usr/home/sound/sea.wav"); + AccessMetadata(exifMetadata, "RowsPerStrip", ""); + AccessMetadata(exifMetadata, "Saturation", "Normal"); + IMAGE_LOGI("%{public}s SUCCESS", __func__); +} + +void MetadataFuncTest004(std::shared_ptr exifMetadata) +{ + IMAGE_LOGI("%{public}s IN", __func__); + if (exifMetadata == nullptr) { + IMAGE_LOGI("%{public}s failed, exifMetadata is null", __func__); + return; + } + AccessMetadata(exifMetadata, "SceneCaptureType", "Standard"); + AccessMetadata(exifMetadata, "SensingMethod", "Two-chip color area sensor"); + AccessMetadata(exifMetadata, "Sharpness", "Normal"); + AccessMetadata(exifMetadata, "ShutterSpeedValue", "13.00 EV (1/8192 sec.)"); + AccessMetadata(exifMetadata, "SourceExposureTimesOfCompositeImage", "."); + AccessMetadata(exifMetadata, "SourceImageNumberOfCompositeImage", "1234"); + AccessMetadata(exifMetadata, "SpatialFrequencyResponse", "."); + AccessMetadata(exifMetadata, "StripByteCounts", ""); + AccessMetadata(exifMetadata, "StripOffsets", ""); + AccessMetadata(exifMetadata, "SubsecTime", "427000"); + AccessMetadata(exifMetadata, "SubsecTimeDigitized", "427000"); + AccessMetadata(exifMetadata, "SubsecTimeOriginal", "427000"); + AccessMetadata(exifMetadata, "SubfileType", ""); + AccessMetadata(exifMetadata, "SubjectArea", + "Within rectangle (width 183, height 259) around (x,y) = (10,20)"); + AccessMetadata(exifMetadata, "SubjectDistanceRange", "Unknown"); + AccessMetadata(exifMetadata, "BodySerialNumber", "xx"); + AccessMetadata(exifMetadata, "BrightnessValue", "2.50 EV (19.38 cd/m^2)"); + AccessMetadata(exifMetadata, "CFAPattern", "1 bytes undefined data"); + AccessMetadata(exifMetadata, "CameraOwnerName", "xx"); + AccessMetadata(exifMetadata, "ColorSpace", "Adobe RGB"); + AccessMetadata(exifMetadata, "ComponentsConfiguration", ""); + AccessMetadata(exifMetadata, "CompositeImage", "1"); + AccessMetadata(exifMetadata, "CompressedBitsPerPixel", "1.5"); + AccessMetadata(exifMetadata, "Contrast", "Normal"); + AccessMetadata(exifMetadata, "CustomRendered", "Custom process"); + AccessMetadata(exifMetadata, "DateTimeDigitized", "2023:01:19 10:39:58"); + AccessMetadata(exifMetadata, "DeviceSettingDescription", "."); + AccessMetadata(exifMetadata, "DigitalZoomRatio", "321"); + AccessMetadata(exifMetadata, "ExifVersion", ""); + AccessMetadata(exifMetadata, "ExposureIndex", "1.5"); + AccessMetadata(exifMetadata, "ExposureMode", "Auto exposure"); + AccessMetadata(exifMetadata, "ExposureProgram", "Normal program"); + AccessMetadata(exifMetadata, "FileSource", "DSC"); + AccessMetadata(exifMetadata, "FlashEnergy", "832"); + AccessMetadata(exifMetadata, "FlashpixVersion", ""); + AccessMetadata(exifMetadata, "FocalPlaneResolutionUnit", "Centimeter"); + AccessMetadata(exifMetadata, "FocalPlaneXResolution", "1080"); + AccessMetadata(exifMetadata, "FocalPlaneYResolution", "880"); + IMAGE_LOGI("%{public}s SUCCESS", __func__); +} + +void MetadataFuncTest005(std::shared_ptr exifMetadata) +{ + IMAGE_LOGI("%{public}s IN", __func__); + if (exifMetadata == nullptr) { + IMAGE_LOGI("%{public}s failed, exifMetadata is null", __func__); + return; + } + AccessMetadata(exifMetadata, "BitsPerSample", "8, 8, 8"); + AccessMetadata(exifMetadata, "Orientation", "Unknown value 0"); + AccessMetadata(exifMetadata, "ImageLength", "4000"); + AccessMetadata(exifMetadata, "ImageWidth", "3000"); + AccessMetadata(exifMetadata, "GPSLatitude", ""); + AccessMetadata(exifMetadata, "GPSLongitude", ""); + AccessMetadata(exifMetadata, "GPSLatitudeRef", ""); + AccessMetadata(exifMetadata, "GPSLongitudeRef", ""); + AccessMetadata(exifMetadata, "DateTimeOriginal", "2024:01:11 09:39:58"); + AccessMetadata(exifMetadata, "ExposureTime", "1/590 sec."); + AccessMetadata(exifMetadata, "SceneType", "Directly photographed"); + AccessMetadata(exifMetadata, "ISOSpeedRatings", "160"); + AccessMetadata(exifMetadata, "FNumber", "f/2.0"); + AccessMetadata(exifMetadata, "DateTime", ""); + AccessMetadata(exifMetadata, "GPSTimeStamp", "01:39:58.00"); + AccessMetadata(exifMetadata, "GPSDateStamp", "2024:01:11"); + AccessMetadata(exifMetadata, "ImageDescription", "_cuva"); + AccessMetadata(exifMetadata, "Make", ""); + AccessMetadata(exifMetadata, "Model", ""); + AccessMetadata(exifMetadata, "SensitivityType", ""); + AccessMetadata(exifMetadata, "StandardOutputSensitivity", ""); + AccessMetadata(exifMetadata, "RecommendedExposureIndex", ""); + AccessMetadata(exifMetadata, "ApertureValue", "2.00 EV (f/2.0)"); + AccessMetadata(exifMetadata, "ExposureBiasValue", "0.00 EV"); + AccessMetadata(exifMetadata, "MeteringMode", "Pattern"); + AccessMetadata(exifMetadata, "LightSource", "Daylight"); + AccessMetadata(exifMetadata, "Flash", "Flash did not fire"); + AccessMetadata(exifMetadata, "FocalLength", "6.3 mm"); + AccessMetadata(exifMetadata, "UserComment", ""); + AccessMetadata(exifMetadata, "PixelXDimension", "4000"); + AccessMetadata(exifMetadata, "PixelYDimension", "3000"); + AccessMetadata(exifMetadata, "WhiteBalance", "Auto white balance"); + AccessMetadata(exifMetadata, "FocalLengthIn35mmFilm", "27"); + AccessMetadata(exifMetadata, "JPEGProc", ""); + IMAGE_LOGI("%{public}s SUCCESS", __func__); +} void MetadataAccessorFuncTest001(std::shared_ptr& metadataAccessor) { @@ -60,9 +294,11 @@ void MetadataAccessorFuncTest001(std::shared_ptr& metadataAcce return; } std::string key = "ImageWidth"; - exifMetadata->SetValue(key, "500"); - std::string value; - exifMetadata->GetValue(key, value); + MetadataFuncTest001(exifMetadata); + MetadataFuncTest002(exifMetadata); + MetadataFuncTest003(exifMetadata); + MetadataFuncTest004(exifMetadata); + MetadataFuncTest005(exifMetadata); metadataAccessor->Write(); metadataAccessor->Set(exifMetadata); DataBuf inputBuf; @@ -70,10 +306,10 @@ void MetadataAccessorFuncTest001(std::shared_ptr& metadataAcce metadataAccessor->WriteBlob(inputBuf); } -void JpegAccessorTest(const uint8_t *data, size_t size) +void JpegAccessorTest(const std::string& pathName) { IMAGE_LOGI("%{public}s IN", __func__); - auto metadataAccessor = MetadataAccessorFactory::Create(JPEG_EXIF_PATH); + auto metadataAccessor = MetadataAccessorFactory::Create(pathName); if (metadataAccessor == nullptr) { IMAGE_LOGI("%{public}s failed", __func__); return; @@ -91,10 +327,10 @@ void JpegAccessorTest(const uint8_t *data, size_t size) IMAGE_LOGI("%{public}s SUCCESS", __func__); } -void PngAccessorTest(const uint8_t *data, size_t size) +void PngAccessorTest(const std::string& pathName) { IMAGE_LOGI("%{public}s IN", __func__); - auto metadataAccessor = MetadataAccessorFactory::Create(PNG_EXIF_PATH); + auto metadataAccessor = MetadataAccessorFactory::Create(pathName); if (metadataAccessor == nullptr) { IMAGE_LOGI("%{public}s failed", __func__); return; @@ -107,10 +343,10 @@ void PngAccessorTest(const uint8_t *data, size_t size) IMAGE_LOGI("%{public}s SUCCESS", __func__); } -void WebpAccessorTest(const uint8_t *data, size_t size) +void WebpAccessorTest(const std::string& pathName) { IMAGE_LOGI("%{public}s IN", __func__); - auto metadataAccessor = MetadataAccessorFactory::Create(WEBP_EXIF_PATH); + auto metadataAccessor = MetadataAccessorFactory::Create(pathName); if (metadataAccessor == nullptr) { IMAGE_LOGI("%{public}s failed", __func__); return; @@ -128,10 +364,10 @@ void WebpAccessorTest(const uint8_t *data, size_t size) IMAGE_LOGI("%{public}s SUCCESS", __func__); } -void HeifAccessorTest(const uint8_t *data, size_t size) +void HeifAccessorTest(const std::string& pathName) { IMAGE_LOGI("%{public}s IN", __func__); - auto metadataAccessor = MetadataAccessorFactory::Create(HEIF_EXIF_PATH); + auto metadataAccessor = MetadataAccessorFactory::Create(pathName); if (metadataAccessor == nullptr) { IMAGE_LOGI("%{public}s failed", __func__); return; @@ -143,10 +379,10 @@ void HeifAccessorTest(const uint8_t *data, size_t size) IMAGE_LOGI("%{public}s SUCCESS", __func__); } -void DngAccessorTest(const uint8_t *data, size_t size) +void DngAccessorTest(const std::string& pathName) { IMAGE_LOGI("%{public}s IN", __func__); - auto metadataAccessor = MetadataAccessorFactory::Create(DNG_EXIF_PATH); + auto metadataAccessor = MetadataAccessorFactory::Create(pathName); if (metadataAccessor == nullptr) { IMAGE_LOGI("%{public}s failed", __func__); return; @@ -170,13 +406,18 @@ void DataBufTest(const uint8_t *data, size_t size) dataBuf.Reset(); } -void AccessorTest001(const uint8_t *data, size_t size) +void AccessorTest001() { - JpegAccessorTest(data, size); - PngAccessorTest(data, size); - WebpAccessorTest(data, size); - HeifAccessorTest(data, size); - DngAccessorTest(data, size); + static const std::string JPEG_EXIF_PATH = "/data/local/tmp/test_exif.jpg"; + static const std::string PNG_EXIF_PATH = "/data/local/tmp/test_exif.png"; + static const std::string WEBP_EXIF_PATH = "/data/local/tmp/test_exif.webp"; + static const std::string HEIF_EXIF_PATH = "/data/local/tmp/test_exif.heic"; + static const std::string DNG_EXIF_PATH = "/data/local/tmp/test_exif.dng"; + JpegAccessorTest(JPEG_EXIF_PATH); + PngAccessorTest(PNG_EXIF_PATH); + WebpAccessorTest(WEBP_EXIF_PATH); + HeifAccessorTest(HEIF_EXIF_PATH); + DngAccessorTest(DNG_EXIF_PATH); } void AccessorTest002(const uint8_t* data, size_t size) @@ -201,7 +442,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { /* Run your code on data */ OHOS::Media::DataBufTest(data, size); - OHOS::Media::AccessorTest001(data, size); + OHOS::Media::AccessorTest001(); OHOS::Media::AccessorTest002(data, size); return 0; } \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapfotmat2_fuzzer/include/image_fwk_decode_ext_format_fuzzer.h b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb2_fuzzer/include/image_fwk_convert_p010yuv2rgb_fuzzer.h similarity index 73% rename from frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapfotmat2_fuzzer/include/image_fwk_decode_ext_format_fuzzer.h rename to frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb2_fuzzer/include/image_fwk_convert_p010yuv2rgb_fuzzer.h index 5ea69ef6a8314af4c65b77d8fec5fe14840d5257..4fcfc9d51c3b7734501c43398d009a30aaafad0a 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapfotmat2_fuzzer/include/image_fwk_decode_ext_format_fuzzer.h +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb2_fuzzer/include/image_fwk_convert_p010yuv2rgb_fuzzer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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 @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef IMAGE_FWK_DECODE_EXT_FUZZ_H -#define IMAGE_FWK_DECODE_EXT_FUZZ_H +#ifndef IMAGE_FWK_CONVERT_P010YUV2RGB_FUZZER_H +#define IMAGE_FWK_CONVERT_P010YUV2RGB_FUZZER_H -#define FUZZ_PROJECT_NAME "image_fwk_decode_ext_fuzzer" +#define FUZZ_PROJECT_NAME "image_fwk_convert_p010yuv2rgb_fuzzer" #endif \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb2_fuzzer/src/image_fwk_convert_p010yuv2rgb_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb2_fuzzer/src/image_fwk_convert_p010yuv2rgb_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c93c572f9af523a0264a924ac037d7d1148d03a --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb2_fuzzer/src/image_fwk_convert_p010yuv2rgb_fuzzer.cpp @@ -0,0 +1,158 @@ +/* + * 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 +#define private public +#include "image_fwk_convert_p010yuv2rgb_fuzzer.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "buffer_packer_stream.h" +#include "image_format_convert.h" +#include "image_log.h" +#include "image_source.h" +#include "image_type.h" +#include "image_utils.h" +#include "media_errors.h" +#include "pixel_map.h" +#include "message_parcel.h" + +constexpr uint32_t MAX_LENGTH_MODULO = 0xfff; +constexpr uint32_t PIXELFORMAT_MODULO = 105; +constexpr uint32_t ALPHATYPE_MODULO = 4; +constexpr uint32_t SCALEMODE_MODULO = 2; + +namespace OHOS { +namespace Media { +FuzzedDataProvider* FDP; + +void YuvP010ToRgbFuzzTest001() +{ + PixelFormat destFormat = static_cast(FDP->ConsumeIntegral() % PIXELFORMAT_MODULO); + + Media::InitializationOptions opts; + opts.size.width = FDP->ConsumeIntegral() % MAX_LENGTH_MODULO; + opts.size.height = FDP->ConsumeIntegral() % MAX_LENGTH_MODULO; + opts.srcPixelFormat = static_cast(FDP->ConsumeIntegral() % PIXELFORMAT_MODULO); + opts.pixelFormat = static_cast(FDP->ConsumeIntegral() % PIXELFORMAT_MODULO); + opts.alphaType = static_cast(FDP->ConsumeIntegral() % ALPHATYPE_MODULO); + opts.scaleMode = static_cast(FDP->ConsumeIntegral() % SCALEMODE_MODULO); + opts.editable = FDP->ConsumeBool(); + opts.useSourceIfMatch = FDP->ConsumeBool(); + int32_t pixelbytes = Media::ImageUtils::GetPixelBytes(opts.srcPixelFormat); + size_t datalength = opts.size.width * opts.size.height * pixelbytes; + std::unique_ptr colorData = std::make_unique(datalength); + if(colorData == nullptr) + return; + FDP->ConsumeData(colorData.get(), datalength); + auto pixelmap = Media::PixelMap::Create(reinterpret_cast(colorData.get()), datalength, opts); + if(pixelmap.get() ==nullptr) + return; + + std::shared_ptr srcPixelMap = std::move(pixelmap); + uint32_t ret = ImageFormatConvert::ConvertImageFormat(srcPixelMap, destFormat); + if (ret != SUCCESS) { + srcPixelMap->FreePixelMap(); + IMAGE_LOGE("YuvP010ConvertToRgb: CreatePixelMap fail"); + return; + } + + srcPixelMap->rotate(FDP->ConsumeFloatingPoint()); + srcPixelMap->scale(FDP->ConsumeIntegral() % MAX_LENGTH_MODULO, FDP->ConsumeIntegral() % MAX_LENGTH_MODULO); + srcPixelMap->FreePixelMap(); +} + +void PixelMapMarshallingTest001() +{ + Media::InitializationOptions opts; + opts.size.width = FDP->ConsumeIntegral() % MAX_LENGTH_MODULO; + opts.size.height = FDP->ConsumeIntegral() % MAX_LENGTH_MODULO; + opts.srcPixelFormat = static_cast(FDP->ConsumeIntegral() % PIXELFORMAT_MODULO); + opts.pixelFormat = static_cast(FDP->ConsumeIntegral() % PIXELFORMAT_MODULO); + opts.alphaType = static_cast(FDP->ConsumeIntegral() % ALPHATYPE_MODULO); + opts.scaleMode = static_cast(FDP->ConsumeIntegral() % SCALEMODE_MODULO); + opts.editable = FDP->ConsumeBool(); + opts.useSourceIfMatch = FDP->ConsumeBool(); + int32_t pixelbytes = Media::ImageUtils::GetPixelBytes(opts.srcPixelFormat); + size_t datalength = opts.size.width * opts.size.height * pixelbytes; + std::unique_ptr colorData = std::make_unique(datalength); + if(colorData == nullptr) + return; + FDP->ConsumeData(colorData.get(), datalength); + auto pixelmap = Media::PixelMap::Create(reinterpret_cast(colorData.get()), datalength, opts); + if(pixelmap.get() == nullptr) + return; + + MessageParcel parcel; + pixelmap->SetMemoryName("MarshallingPixelMap"); + if (!pixelmap->Marshalling(parcel)) { + IMAGE_LOGI("g_pixelMapIpcTest Marshalling failed id: %{public}d, isUnmap: %{public}d", + pixelmap->GetUniqueId(), pixelmap->IsUnMap()); + return; + } +} + +void PixelMapUnmarshallingTest001() +{ + MessageParcel parcel; + size_t size = FDP->remaining_bytes(); + void* data = malloc(size); + if(data == nullptr) + return; + FDP->ConsumeData(data, size); + parcel.WriteBuffer(data, size); + + Media::PixelMap* unmarshallingPixelmap = Media::PixelMap::Unmarshalling(parcel); + if (!unmarshallingPixelmap) { + free(data); + return; + } + unmarshallingPixelmap->SetMemoryName("unmarshallingPixelMap"); + IMAGE_LOGI("g_pixelMapIpcTest unmarshallingPixelMap failed id: %{public}d, isUnmap: %{public}d", + unmarshallingPixelmap->GetUniqueId(), unmarshallingPixelmap->IsUnMap()); + unmarshallingPixelmap->FreePixelMap(); + delete unmarshallingPixelmap; + unmarshallingPixelmap = nullptr; + free(data); + return; +} + +void YuvP010PixelMapIPCFuzzTest001() +{ + PixelMapMarshallingTest001(); + PixelMapUnmarshallingTest001(); +} + +} // namespace Media +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + FuzzedDataProvider fdp(data, size); + OHOS::Media::FDP = &fdp; + OHOS::Media::YuvP010ToRgbFuzzTest001(); + OHOS::Media::YuvP010PixelMapIPCFuzzTest001(); + return 0; +} diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f6b0dcf16bd843dc79b31af356c86b366fa7f8f3 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/BUILD.gn @@ -0,0 +1,39 @@ +# 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("ImageFwkConvertP010Yuv2RgbFuzzTest") { + module_out_path = "multimedia_image/image_framework" + fuzz_config_file = "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer" + resource_config_file = "$image_subsystem/test/resource/image/ohos_test.xml" + + include_dirs = [ + "./include", + "$image_subsystem/interfaces/innerkits/include", + "$image_subsystem/frameworks/innerkitsimpl/converter/include", + ] + + sources = [ "src/image_fwk_convert_p010yuv2rgb_fuzzer.cpp" ] + + defines = [ "EXT_PIXEL" ] + + deps = [ "$image_subsystem/interfaces/innerkits:image_native" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/include/image_fwk_convert_p010yuv2rgb_fuzzer.h b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/include/image_fwk_convert_p010yuv2rgb_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..4fcfc9d51c3b7734501c43398d009a30aaafad0a --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/include/image_fwk_convert_p010yuv2rgb_fuzzer.h @@ -0,0 +1,19 @@ +/* + * 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. + */ +#ifndef IMAGE_FWK_CONVERT_P010YUV2RGB_FUZZER_H +#define IMAGE_FWK_CONVERT_P010YUV2RGB_FUZZER_H + +#define FUZZ_PROJECT_NAME "image_fwk_convert_p010yuv2rgb_fuzzer" +#endif \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/project.xml b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..8b63c0e579ed4235d4d1d440b94ecb78aac04050 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 52428800 + + 300 + + 4096 + + diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/src/image_fwk_convert_p010yuv2rgb_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/src/image_fwk_convert_p010yuv2rgb_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0c51c2b5550214704c5f99e7074ebd37d0a4611b --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertp010yuv2rgb_fuzzer/src/image_fwk_convert_p010yuv2rgb_fuzzer.cpp @@ -0,0 +1,459 @@ +/* + * 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. + */ + +#define private public +#include "image_fwk_convert_p010yuv2rgb_fuzzer.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "buffer_packer_stream.h" +#include "image_format_convert.h" +#include "image_format_convert_utils.h" +#include "image_log.h" +#include "image_source.h" +#include "image_type.h" +#include "image_utils.h" +#include "media_errors.h" +#include "pixel_map.h" +#include "message_parcel.h" + +namespace OHOS { +namespace Media { + +constexpr int32_t P010_ORIGINAL_WIDTH = 1920; +constexpr int32_t P010_ORIGINAL_HEIGHT = 1080; +constexpr uint32_t BYTES_PER_PIXEL_RGB565 = 2; +constexpr uint32_t BYTES_PER_PIXEL_RGB = 3; +constexpr uint32_t BYTES_PER_PIXEL_RGBA = 4; +constexpr uint32_t BYTES_PER_PIXEL_BGRA = 4; +constexpr uint32_t EVEN_ODD_DIVISOR = 2; +constexpr uint32_t TWO_SLICES = 2; +constexpr int32_t NUM_2 = 2; + +struct ImageSize { + int32_t width = 0; + int32_t height = 0; + float dstWidth = 0; + float dstHeight = 0; + const uint32_t color = 0; + uint32_t dst = 0; +}; + +static const std::string IMAGE_INPUT_YUV_PATH3 = "/data/local/tmp/P010.yuv"; + +bool ReadFile(void *chOrg, std::string path, int32_t totalsize, int32_t srcNum) +{ + FILE* const fileOrg = fopen(path.c_str(), "rb"); + if (fileOrg == nullptr) { + return false; + } + if (srcNum == 0) { + size_t bytesOrg = fread(chOrg, sizeof(uint8_t), static_cast(totalsize), fileOrg); + if (bytesOrg < static_cast(totalsize)) { + fclose(fileOrg); + return false; + } + } else { + size_t bytesOrg = fread(chOrg, sizeof(uint16_t), static_cast(totalsize), fileOrg); + if (bytesOrg < static_cast(totalsize)) { + fclose(fileOrg); + return false; + } + } + fclose(fileOrg); + return true; +} + +void YuvP010ConvertToRgb(PixelFormat &srcFormat, PixelFormat &destFormat, Size &srcSize, + uint32_t destBuffersize) +{ + IMAGE_LOGI("YuvP010ConvertToRgb: start"); + ImageSize imageSize; + imageSize.width = srcSize.width; + imageSize.height = srcSize.height; + int32_t ySize = imageSize.width * imageSize.height; + int32_t uvSize = ((imageSize.width + 1) / NUM_2) * ((imageSize.height + 1) / NUM_2); + const size_t totalSize = (ySize + NUM_2 * uvSize); + uint16_t* const chOrg = new uint16_t[totalSize]; + bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH3, totalSize, 1); + if (!result) { + delete[] chOrg; + return; + } + const uint32_t dataLength = totalSize * NUM_2; + uint32_t *data = reinterpret_cast(chOrg); + InitializationOptions opts; + opts.srcPixelFormat = srcFormat; + opts.pixelFormat = srcFormat; + opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; + opts.size.width = imageSize.width; + opts.size.height = imageSize.height; + std::unique_ptr pixelMap = PixelMap::Create(data, dataLength, opts); + if (pixelMap.get() == nullptr) { + delete[] chOrg; + return; + } + delete[] chOrg; + std::shared_ptr srcPixelMap = std::move(pixelMap); + uint32_t ret = ImageFormatConvert::ConvertImageFormat(srcPixelMap, destFormat); + if (ret != SUCCESS || srcPixelMap->GetPixelFormat() != destFormat) { + srcPixelMap->FreePixelMap(); + IMAGE_LOGE("YuvP010ConvertToRgb: CreatePixelMap fail"); + return; + } + srcPixelMap->FreePixelMap(); + IMAGE_LOGI("YuvP010ConvertToRgb: succ"); +} + +void NV12P010ToNV12FuzzTest003() +{ + IMAGE_LOGI("NV12P010ToNV12FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + PixelFormat destFormat = PixelFormat::NV12; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height + ((srcSize.width + 1) / EVEN_ODD_DIVISOR) * + ((srcSize.height + 1) / EVEN_ODD_DIVISOR) * TWO_SLICES; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToNV12FuzzTest003: end"); +} + +void NV12P010ToNV21FuzzTest003() +{ + IMAGE_LOGI("NV12P010ToNV21FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + PixelFormat destFormat = PixelFormat::NV21; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height + ((srcSize.width + 1) / EVEN_ODD_DIVISOR) * + ((srcSize.height + 1) / EVEN_ODD_DIVISOR) * TWO_SLICES; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToNV21FuzzTest003: end"); +} + +void NV12P010ToNV21P010FuzzTest003() +{ + IMAGE_LOGI("NV12P010ToNV21P010FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + PixelFormat destFormat = PixelFormat::YCRCB_P010; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = (srcSize.width * srcSize.height + ((srcSize.width + 1) / EVEN_ODD_DIVISOR) * + ((srcSize.height + 1) / EVEN_ODD_DIVISOR) * TWO_SLICES) * TWO_SLICES; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToNV21P010FuzzTest003: end"); +} + +void NV12P010ToRGB565FuzzTest003() +{ + IMAGE_LOGI("NV12P010ToRGB565FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + PixelFormat destFormat = PixelFormat::RGB_565; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_RGB565; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToRGB565FuzzTest003: end"); +} + +void NV12P010ToRGBAFuzzTest003() +{ + IMAGE_LOGI("NV12P010ToRGBAFuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + PixelFormat destFormat = PixelFormat::RGBA_8888; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_RGBA; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToRGBAFuzzTest003: end"); +} + +void NV12P010ToBGRAFuzzTest003() +{ + IMAGE_LOGI("NV12P010ToBGRAFuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + PixelFormat destFormat = PixelFormat::BGRA_8888; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_BGRA; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToBGRAFuzzTest003: end"); +} + +void NV12P010ToRGBFuzzTest003() +{ + IMAGE_LOGI("NV12P010ToRGBFuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + PixelFormat destFormat = PixelFormat::RGB_888; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_RGB; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToRGBFuzzTest003: end"); +} + +void NV12P010ToRGBAF16FuzzTest003() +{ + IMAGE_LOGI("NV12P010ToRGBAF16FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + PixelFormat destFormat = PixelFormat::RGBA_F16; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * sizeof(uint64_t); + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToRGBAF16FuzzTest003: end"); +} + +void NV21P010ToNV21FuzzTest003() +{ + IMAGE_LOGI("NV21P010ToNV21FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + PixelFormat destFormat = PixelFormat::NV21; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height + ((srcSize.width + 1) / EVEN_ODD_DIVISOR) * + ((srcSize.height + 1) / EVEN_ODD_DIVISOR) * TWO_SLICES; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV21P010ToNV21FuzzTest003: end"); +} + +void NV12P010ToNV12P010FuzzTest003() +{ + IMAGE_LOGI("NV12P010ToNV12P010FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + PixelFormat destFormat = PixelFormat::YCBCR_P010; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = (srcSize.width * srcSize.height + ((srcSize.width + 1) / EVEN_ODD_DIVISOR) * + ((srcSize.height + 1) / EVEN_ODD_DIVISOR) * TWO_SLICES) * TWO_SLICES; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToNV12P010FuzzTest003: end"); +} + +void NV21P010ToRGB565FuzzTest003() +{ + IMAGE_LOGI("NV21P010ToRGB565FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + PixelFormat destFormat = PixelFormat::RGB_565; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_RGB565; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV21P010ToRGB565FuzzTest003: end"); +} + +void NV21P010ToRGBAFuzzTest003() +{ + IMAGE_LOGI("NV21P010ToRGBAFuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + PixelFormat destFormat = PixelFormat::RGBA_8888; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_RGBA; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV21P010ToRGBAFuzzTest003: end"); +} + +void NV21P010ToBGRAFuzzTest003() +{ + IMAGE_LOGI("NV21P010ToBGRAFuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + PixelFormat destFormat = PixelFormat::BGRA_8888; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_BGRA; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV21P010ToBGRAFuzzTest003: end"); +} + +void NV21P010ToRGBFuzzTest003() +{ + IMAGE_LOGI("NV21P010ToRGBFuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + PixelFormat destFormat = PixelFormat::RGB_888; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_RGB; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV21P010ToRGBFuzzTest003: end"); +} + +void NV21P010ToRGBAF16FuzzTest003() +{ + IMAGE_LOGI("NV21P010ToRGBAF16FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + PixelFormat destFormat = PixelFormat::RGBA_F16; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * sizeof(uint64_t); + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV21P010ToRGBAF16FuzzTest003: end"); +} + +void NV12P010ToRGBA1010102FuzzTest004() +{ + IMAGE_LOGI("NV12P010ToRGBA_1010102FuzzTest004: start"); + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + PixelFormat destFormat = PixelFormat::RGBA_1010102; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_RGBA; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV12P010ToRGBA_1010102FuzzTest004: end"); +} + +void NV21P010ToRGBA1010102FuzzTest004() +{ + IMAGE_LOGI("NV21P010ToRGBA_1010102FuzzTest004: start"); + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + PixelFormat destFormat = PixelFormat::RGBA_1010102; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height * BYTES_PER_PIXEL_RGBA; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV21P010ToRGBA_1010102FuzzTest004: end"); +} + +void NV21P010ToNV12FuzzTest003() +{ + IMAGE_LOGI("NV21P010ToNV12FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + PixelFormat destFormat = PixelFormat::NV12; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + uint32_t destBuffersize = srcSize.width * srcSize.height + ((srcSize.width + 1) / EVEN_ODD_DIVISOR) * + ((srcSize.height + 1) / EVEN_ODD_DIVISOR) * TWO_SLICES; + YuvP010ConvertToRgb(srcFormat, destFormat, srcSize, destBuffersize); + IMAGE_LOGI("NV21P010ToNV12FuzzTest003: end"); +} + +void YuvP010ToRgbFuzzTest001() +{ + IMAGE_LOGI("YuvP010ToRgbTest001: start"); + NV12P010ToNV12FuzzTest003(); + NV12P010ToNV21FuzzTest003(); + NV12P010ToNV21P010FuzzTest003(); + NV12P010ToRGB565FuzzTest003(); + NV12P010ToRGBAFuzzTest003(); + NV12P010ToBGRAFuzzTest003(); + NV12P010ToRGBFuzzTest003(); + NV12P010ToRGBAF16FuzzTest003(); + NV21P010ToNV12FuzzTest003(); + NV21P010ToNV21FuzzTest003(); + NV12P010ToNV12P010FuzzTest003(); + NV21P010ToRGB565FuzzTest003(); + NV21P010ToRGBAFuzzTest003(); + NV21P010ToBGRAFuzzTest003(); + NV21P010ToRGBFuzzTest003(); + NV21P010ToRGBAF16FuzzTest003(); + NV12P010ToRGBA1010102FuzzTest004(); + NV21P010ToRGBA1010102FuzzTest004(); + IMAGE_LOGI("YuvP010ToRgbTest001: end"); +} + +/* + * test pixelmap IPC interface + */ +bool g_pixelMapIpcTest(std::unique_ptr &pixelMap) +{ + if (!pixelMap) { + return false; + } + // test parcel pixelmap + MessageParcel parcel; + pixelMap->SetMemoryName("MarshallingPixelMap"); + if (!pixelMap->Marshalling(parcel)) { + IMAGE_LOGI("g_pixelMapIpcTest Marshalling failed id: %{public}d, isUnmap: %{public}d", + pixelMap->GetUniqueId(), pixelMap->IsUnMap()); + return false; + } + Media::PixelMap* unmarshallingPixelMap = Media::PixelMap::Unmarshalling(parcel); + if (!unmarshallingPixelMap) { + return false; + } + unmarshallingPixelMap->SetMemoryName("unmarshallingPixelMap"); + IMAGE_LOGI("g_pixelMapIpcTest unmarshallingPixelMap failed id: %{public}d, isUnmap: %{public}d", + unmarshallingPixelMap->GetUniqueId(), unmarshallingPixelMap->IsUnMap()); + unmarshallingPixelMap->FreePixelMap(); + delete unmarshallingPixelMap; + unmarshallingPixelMap = nullptr; + return true; +} + +std::unique_ptr GetYuvP010PixelMap(PixelFormat &srcFormat, Size &srcSize) +{ + IMAGE_LOGI("GetYuvP010PixelMap: start"); + ImageSize imageSize; + imageSize.width = srcSize.width; + imageSize.height = srcSize.height; + int32_t ySize = imageSize.width * imageSize.height; + int32_t uvSize = ((imageSize.width + 1) / NUM_2) * ((imageSize.height + 1) / NUM_2); + const size_t totalSize = (ySize + NUM_2 * uvSize); + uint16_t* const chOrg = new uint16_t[totalSize]; + bool result = ReadFile(chOrg, IMAGE_INPUT_YUV_PATH3, totalSize, 1); + if (!result) { + IMAGE_LOGE("GetYuvPixelMap: ReadFile fail"); + delete[] chOrg; + return nullptr; + } + const uint32_t dataLength = totalSize * NUM_2; + uint32_t *data = reinterpret_cast(chOrg); + InitializationOptions opts; + opts.srcPixelFormat = srcFormat; + opts.pixelFormat = srcFormat; + opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; + opts.size.width = imageSize.width; + opts.size.height = imageSize.height; + std::unique_ptr pixelMap = PixelMap::Create(data, dataLength, opts); + if (pixelMap.get() == nullptr) { + delete[] chOrg; + IMAGE_LOGE("GetYuvPixelMap: Create fail"); + return nullptr; + } + delete[] chOrg; + return pixelMap; +} + +void NV12P010PixelMapIPCTest001() +{ + PixelFormat srcFormat = PixelFormat::YCBCR_P010; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + std::unique_ptr yuvP010PixelMap = GetYuvP010PixelMap(srcFormat, srcSize); + g_pixelMapIpcTest(yuvP010PixelMap); +} + +void NV21P010PixelMapIPCTest001() +{ + PixelFormat srcFormat = PixelFormat::YCRCB_P010; + Size srcSize = { P010_ORIGINAL_WIDTH, P010_ORIGINAL_HEIGHT }; + std::unique_ptr yuvP010PixelMap = GetYuvP010PixelMap(srcFormat, srcSize); + g_pixelMapIpcTest(yuvP010PixelMap); +} + +void YuvP010PixelMapIPCFuzzTest001() +{ + NV12P010PixelMapIPCTest001(); + NV21P010PixelMapIPCTest001(); +} + +} // namespace Media +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + int fd = open(OHOS::Media::IMAGE_INPUT_YUV_PATH3.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (write(fd, data, size) != (ssize_t)size) { + close(fd); + IMAGE_LOGE("Fuzzer copy data fail"); + return 0; + } + close(fd); + OHOS::Media::YuvP010ToRgbFuzzTest001(); + OHOS::Media::YuvP010PixelMapIPCFuzzTest001(); + return 0; +} \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapfotmat_fuzzer/include/image_fwk_convert_pixelmap_format_fuzzer.h b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat2_fuzzer/include/image_fwk_convert_pixelmap_format_fuzzer.h similarity index 100% rename from frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapfotmat_fuzzer/include/image_fwk_convert_pixelmap_format_fuzzer.h rename to frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat2_fuzzer/include/image_fwk_convert_pixelmap_format_fuzzer.h diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat2_fuzzer/project.xml b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat2_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..9e45ec209599971e6208d1eb5abd49116dd2a00b --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat2_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 2000 + + 300 + + 8192 + + diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat2_fuzzer/src/image_fwk_convert_pixelmap_format_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat2_fuzzer/src/image_fwk_convert_pixelmap_format_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f11731b138a256c83b4463e9964efe708270bbfb --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat2_fuzzer/src/image_fwk_convert_pixelmap_format_fuzzer.cpp @@ -0,0 +1,138 @@ +/* + * 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 +#define private public +#include "image_fwk_convert_pixelmap_format_fuzzer.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "buffer_packer_stream.h" +#include "image_format_convert.h" +#include "image_log.h" +#include "image_source.h" +#include "image_type.h" +#include "image_utils.h" +#include "media_errors.h" + +constexpr uint32_t PIXELFORMAT_MODULO = 105; +constexpr uint32_t COLORSPACE_MODULO = 17; +constexpr uint32_t SCALEMODE_MODULO = 2; +constexpr uint32_t DYNAMICRANGE_MODULO = 3; +constexpr uint32_t RESOLUTION_MODULO = 4; +constexpr uint32_t MIMTTYPE_MODULO = 16; +constexpr uint32_t ALPHATYPE_MODULO = 4; +constexpr uint32_t OPT_SIZE = 80; + +namespace OHOS { +namespace Media { +FuzzedDataProvider* FDP; +static const std::string IMAGE_INPUT_JPG_PATH1 = "/data/local/tmp/test.jpg"; + +void PixelMapFormattotalFuzzTest001() +{ + std::string mimeType[] = {"image/png" , "image/raw" , "image/vnd.wap.wbmp" , "image/bmp" , "image/gif" , "image/jpeg" , "image/mpo" , "image/jpeg" , "image/jpeg" , "image/heif" , "image/heif" , "image/x-adobe-dng" , "image/webp" , "image/tiff" , "image/x-icon" , "image/x-sony-arw"}; + + uint32_t errorCode = 0; + SourceOptions srcopts; + srcopts.formatHint = mimeType[FDP->ConsumeIntegral() % MIMTTYPE_MODULO]; + std::string jpgPath = IMAGE_INPUT_JPG_PATH1; + std::shared_ptr rImageSource = ImageSource::CreateImageSource(jpgPath, srcopts, errorCode); + if (errorCode != SUCCESS || rImageSource.get() == nullptr) { + IMAGE_LOGE("PixelMapFormatConvert: CreateImageSource fail"); + return; + } + + DecodeOptions decodeOpts; + decodeOpts.fitDensity = FDP->ConsumeIntegral(); + decodeOpts.CropRect.left = FDP->ConsumeIntegral(); + decodeOpts.CropRect.top = FDP->ConsumeIntegral(); + decodeOpts.CropRect.width = FDP->ConsumeIntegral(); + decodeOpts.CropRect.height = FDP->ConsumeIntegral(); + decodeOpts.desiredSize.width = FDP->ConsumeIntegralInRange(0, 0xfff); + decodeOpts.desiredSize.height = FDP->ConsumeIntegralInRange(0, 0xfff); + decodeOpts.desiredRegion.left = FDP->ConsumeIntegral(); + decodeOpts.desiredRegion.top = FDP->ConsumeIntegral(); + decodeOpts.desiredRegion.width = FDP->ConsumeIntegral(); + decodeOpts.desiredRegion.height = FDP->ConsumeIntegral(); + decodeOpts.rotateDegrees = FDP->ConsumeFloatingPoint(); + decodeOpts.rotateNewDegrees = FDP->ConsumeIntegral(); + decodeOpts.sampleSize = FDP->ConsumeIntegral(); + decodeOpts.desiredPixelFormat = static_cast(FDP->ConsumeIntegral() % PIXELFORMAT_MODULO); + decodeOpts.photoDesiredPixelFormat = static_cast(FDP->ConsumeIntegral() % PIXELFORMAT_MODULO); + decodeOpts.desiredColorSpace = static_cast(FDP->ConsumeIntegral() % COLORSPACE_MODULO); + decodeOpts.allowPartialImage = FDP->ConsumeBool(); + decodeOpts.editable = FDP->ConsumeBool(); + decodeOpts.preference = static_cast(FDP->ConsumeBool()); + decodeOpts.fastAstc = FDP->ConsumeBool(); + decodeOpts.invokeType = FDP->ConsumeIntegral(); + decodeOpts.desiredDynamicRange = static_cast(FDP->ConsumeIntegral() % DYNAMICRANGE_MODULO); + decodeOpts.resolutionQuality = static_cast(FDP->ConsumeIntegral() % RESOLUTION_MODULO); + decodeOpts.isAisr = FDP->ConsumeBool(); + decodeOpts.isAppUseAllocator = FDP->ConsumeBool(); + + std::shared_ptr srcPixelMap = rImageSource->CreatePixelMap(decodeOpts, errorCode); + if (errorCode != SUCCESS || srcPixelMap.get() == nullptr) { + IMAGE_LOGE("PixelMapFormatConvert: CreatePixelMap fail"); + return; + } + + uint32_t *data = (uint32_t *)srcPixelMap->GetPixels(); + const uint32_t dataLength = srcPixelMap->GetByteCount(); + InitializationOptions opts; + opts.srcPixelFormat = static_cast(FDP->ConsumeIntegral() % PIXELFORMAT_MODULO); + opts.pixelFormat = static_cast(FDP->ConsumeIntegral() % PIXELFORMAT_MODULO); + opts.alphaType = static_cast(FDP->ConsumeIntegral() % ALPHATYPE_MODULO); + opts.scaleMode = static_cast(FDP->ConsumeIntegral() % SCALEMODE_MODULO); + opts.editable = FDP->ConsumeBool(); + opts.useSourceIfMatch = FDP->ConsumeBool(); + + std::unique_ptr pixelMap = PixelMap::Create(data, dataLength, opts); + if (pixelMap.get() == nullptr) { + IMAGE_LOGE("PixelMapFormatConvert: PixelMap::Create fail"); + return; + } +} + +} // 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 < OPT_SIZE) return -1; + FuzzedDataProvider fdp(data + size - OPT_SIZE, OPT_SIZE); + OHOS::Media::FDP = &fdp; + + static const std::string pathName = "/data/local/tmp/test.jpg"; + int fd = open(pathName.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (write(fd, data, size - OPT_SIZE) != (ssize_t)size - OPT_SIZE) { + close(fd); + IMAGE_LOGE("Fuzzer copy data fail"); + return 0; + } + close(fd); + OHOS::Media::PixelMapFormattotalFuzzTest001(); + return 0; +} diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapfotmat2_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/BUILD.gn similarity index 88% rename from frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapfotmat2_fuzzer/BUILD.gn rename to frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/BUILD.gn index 7c28af82808334099a8faac0f1e26effed07ad1e..27f155934b2221b99a6e310a8cbacd294e6c9bbf 100644 --- a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapfotmat2_fuzzer/BUILD.gn +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. +# 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 @@ -14,9 +14,9 @@ import("//build/test.gni") import("//foundation/multimedia/image_framework/ide/image_decode_config.gni") -ohos_fuzztest("Imagefwkconvertpixelmapformat2FuzzTest") { +ohos_fuzztest("ImageFwkConvertPixelMapFormatFuzzTest") { module_out_path = "multimedia_image/image_framework" - fuzz_config_file = "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat2_fuzzer" + fuzz_config_file = "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer" resource_config_file = "$image_subsystem/test/resource/image/ohos_test.xml" include_dirs = [ diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/include/image_fwk_convert_pixelmap_format_fuzzer.h b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/include/image_fwk_convert_pixelmap_format_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..59709120227e481e4cb6b7725a3d54821434b005 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/include/image_fwk_convert_pixelmap_format_fuzzer.h @@ -0,0 +1,19 @@ +/* + * 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. + */ +#ifndef IMAGE_FWK_CONVERT_PIXELMAP_FORMAT_FUZZER_H +#define IMAGE_FWK_CONVERT_PIXELMAP_FORMAT_FUZZER_H + +#define FUZZ_PROJECT_NAME "imagefwkconvertpixelmapformat_fuzzer" +#endif \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/project.xml b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..476ca67cd7e43ed8c746c1c35e6f378433e0f753 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 2000 + + 300 + + 8192 + + diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/src/image_fwk_convert_pixelmap_format_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/src/image_fwk_convert_pixelmap_format_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b99c57075b1a2531f24f20623c86608e0939b26c --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertpixelmapformat_fuzzer/src/image_fwk_convert_pixelmap_format_fuzzer.cpp @@ -0,0 +1,143 @@ +/* + * 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. + */ + +#define private public +#include "image_fwk_convert_pixelmap_format_fuzzer.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "buffer_packer_stream.h" +#include "image_format_convert.h" +#include "image_format_convert_utils.h" +#include "image_log.h" +#include "image_source.h" +#include "image_type.h" +#include "image_utils.h" +#include "media_errors.h" + +namespace OHOS { +namespace Media { + +static const std::string IMAGE_INPUT_JPG_PATH1 = "/data/local/tmp/test.jpg"; + +void PixelMapFormatConvert(PixelFormat &srcFormat, PixelFormat &destFormat) +{ + uint32_t errorCode = 0; + SourceOptions srcopts; + srcopts.formatHint = "image/jpeg"; + std::string jpgPath = IMAGE_INPUT_JPG_PATH1; + std::shared_ptr rImageSource = ImageSource::CreateImageSource(jpgPath, srcopts, errorCode); + if (errorCode != SUCCESS || rImageSource.get() == nullptr) { + IMAGE_LOGE("PixelMapFormatConvert: CreateImageSource fail"); + return; + } + + DecodeOptions decodeOpts; + decodeOpts.desiredPixelFormat = srcFormat; + std::shared_ptr srcPixelMap = rImageSource->CreatePixelMap(decodeOpts, errorCode); + if (errorCode != SUCCESS || srcPixelMap.get() == nullptr) { + IMAGE_LOGE("PixelMapFormatConvert: CreatePixelMap fail"); + return; + } + + uint32_t *data = (uint32_t *)srcPixelMap->GetPixels(); + const uint32_t dataLength = srcPixelMap->GetByteCount(); + InitializationOptions opts; + opts.srcPixelFormat = srcFormat; + opts.pixelFormat = destFormat; + opts.alphaType = AlphaType::IMAGE_ALPHA_TYPE_PREMUL; + + std::unique_ptr pixelMap = PixelMap::Create(data, dataLength, opts); + if (pixelMap.get() == nullptr) { + IMAGE_LOGE("PixelMapFormatConvert: PixelMap::Create fail"); + return; + } + IMAGE_LOGI("PixelMapFormatConvert: ConvertImageFormat succ"); +} + +void PixelMapFormatFuzzTest001() +{ + IMAGE_LOGI("PixelMapFormatFuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::YCBCR_P010; + PixelMapFormatConvert(srcFormat, destFormat); + IMAGE_LOGI("PixelMapFormatFuzzTest001: end"); +} + +void PixelMapFormatFuzzTest002() +{ + IMAGE_LOGI("PixelMapFormatFuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::YCRCB_P010; + PixelMapFormatConvert(srcFormat, destFormat); + IMAGE_LOGI("PixelMapFormatFuzzTest002: end"); +} + +void PixelMapFormatFuzzTest003() +{ + IMAGE_LOGI("PixelMapFormatFuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::YCBCR_P010; + PixelMapFormatConvert(srcFormat, destFormat); + IMAGE_LOGI("PixelMapFormatFuzzTest003: end"); +} + +void PixelMapFormatFuzzTest004() +{ + IMAGE_LOGI("PixelMapFormatFuzzTest004: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::YCRCB_P010; + PixelMapFormatConvert(srcFormat, destFormat); + IMAGE_LOGI("PixelMapFormatFuzzTest004: end"); +} + +void PixelMapFormattotalFuzzTest001() +{ + IMAGE_LOGI("PixelMapFormatTest001: start"); + PixelMapFormatFuzzTest001(); + PixelMapFormatFuzzTest002(); + PixelMapFormatFuzzTest003(); + PixelMapFormatFuzzTest004(); + IMAGE_LOGI("PixelMapFormatTest001: end"); +} + +} // namespace Media +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + + static const std::string pathName = "/data/local/tmp/test.jpg"; + int fd = open(pathName.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (write(fd, data, size) != (ssize_t)size) { + close(fd); + IMAGE_LOGE("Fuzzer copy data fail"); + return 0; + } + close(fd); + OHOS::Media::PixelMapFormattotalFuzzTest001(); + return 0; +} \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertrgb2yuvp010_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertrgb2yuvp010_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1f3cf6729fc054cdf8bb5cee015e088d32c6bda9 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertrgb2yuvp010_fuzzer/BUILD.gn @@ -0,0 +1,35 @@ +# 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("ImageFwkConvertRgb2YuvP010FuzzTest") { + module_out_path = "multimedia_image/image_framework" + fuzz_config_file = "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertrgb2yuvp010_fuzzer" + resource_config_file = "$image_subsystem/test/resource/image/ohos_test.xml" + + include_dirs = [ + "./include", + "$image_subsystem/interfaces/innerkits/include", + "$image_subsystem/frameworks/innerkitsimpl/converter/include", + ] + + sources = [ "src/image_fwk_convert_rgb2yuvp010_fuzzer.cpp" ] + + defines = [ "EXT_PIXEL" ] + + deps = [ "$image_subsystem/interfaces/innerkits:image_native" ] + + external_deps = [ "hilog:libhilog" ] +} diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertrgb2yuvp010_fuzzer/project.xml b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertrgb2yuvp010_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..476ca67cd7e43ed8c746c1c35e6f378433e0f753 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertrgb2yuvp010_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 2000 + + 300 + + 8192 + + diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer/BUILD.gn b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e7597f7f626c354ba06923b60870892bf75716ab --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer/BUILD.gn @@ -0,0 +1,39 @@ +# 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("ImageFwkConvertYuv2RgbFuzzTest") { + module_out_path = "multimedia_image/image_framework" + fuzz_config_file = "$image_subsystem/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer" + resource_config_file = "$image_subsystem/test/resource/image/ohos_test.xml" + + include_dirs = [ + "./include", + "$image_subsystem/interfaces/innerkits/include", + "$image_subsystem/frameworks/innerkitsimpl/converter/include", + ] + + sources = [ "src/image_fwk_convert_yuv2rgb_fuzzer.cpp" ] + + defines = [ "EXT_PIXEL" ] + + deps = [ "$image_subsystem/interfaces/innerkits:image_native" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer/project.xml b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..476ca67cd7e43ed8c746c1c35e6f378433e0f753 --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 2000 + + 300 + + 8192 + + diff --git a/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer/src/image_fwk_convert_yuv2rgb_fuzzer.cpp b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer/src/image_fwk_convert_yuv2rgb_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a452acfc1b8cce63324b4314c6624661e5f063bd --- /dev/null +++ b/frameworks/innerkitsimpl/test/fuzztest/imagefwkconvertyuv2rgb_fuzzer/src/image_fwk_convert_yuv2rgb_fuzzer.cpp @@ -0,0 +1,490 @@ +/* + * 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. + */ + +#define private public +#include "image_fwk_convert_yuv2rgb_fuzzer.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "buffer_packer_stream.h" +#include "image_format_convert.h" +#include "image_format_convert_utils.h" +#include "image_log.h" +#include "image_source.h" +#include "image_type.h" +#include "image_utils.h" +#include "media_errors.h" +#include "pixel_map.h" +#include "message_parcel.h" + +namespace OHOS { +namespace Media { + +static const std::string IMAGE_INPUT_JPG_PATH1 = "/data/local/tmp/test.jpg"; + +void YuvConvertToRgb(PixelFormat &srcFormat, PixelFormat &destFormat) +{ + IMAGE_LOGI("YuvConvertToRgb: start"); + uint32_t errorCode = 0; + SourceOptions opts; + opts.formatHint = "image/jpeg"; + std::string jpgPath = IMAGE_INPUT_JPG_PATH1; + std::shared_ptr rImageSource = ImageSource::CreateImageSource(jpgPath, opts, errorCode); + if (errorCode != SUCCESS || rImageSource.get() == nullptr) { + IMAGE_LOGE("YuvConvertToRgb: CreateImageSource fail"); + return; + } + + DecodeOptions decodeOpts; + decodeOpts.desiredPixelFormat = srcFormat; + std::shared_ptr srcPixelMap = rImageSource->CreatePixelMap(decodeOpts, errorCode); + if (errorCode != SUCCESS || srcPixelMap.get() == nullptr) { + IMAGE_LOGE("YuvConvertToRgb: CreatePixelMap fail"); + return; + } + uint32_t ret = ImageFormatConvert::ConvertImageFormat(srcPixelMap, destFormat); + srcPixelMap->FreePixelMap(); + if (ret != SUCCESS) { + IMAGE_LOGE("YuvConvertToRgb: ConvertImageFormat fail"); + return; + } + IMAGE_LOGI("YuvConvertToRgb: succ"); +} + +void NV21ToRGBFuzzTest001() +{ + IMAGE_LOGI("NV21ToRGBFuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::RGB_888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToRGBFuzzTest001: end"); +} + +void NV21ToRGBFuzzTest002() +{ + IMAGE_LOGI("NV21ToRGBFuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::RGB_888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToRGBFuzzTest002: end"); +} + +void NV21ToRGBAFuzzTest001() +{ + IMAGE_LOGI("NV21ToRGBAFuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::RGBA_8888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToRGBAFuzzTest001: end"); +} + +void NV21ToRGBAFuzzTest002() +{ + IMAGE_LOGI("NV21ToRGBAFuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::RGBA_8888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToRGBAFuzzTest002: end"); +} + +void NV21ToBGRAFuzzTest001() +{ + IMAGE_LOGI("NV21ToBGRAFuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::BGRA_8888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToBGRAFuzzTest001: end"); +} + +void NV21ToBGRAFuzzTest002() +{ + IMAGE_LOGI("NV21ToBGRAFuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::BGRA_8888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToBGRAFuzzTest002: end"); +} + +void NV21ToRGB565FuzzTest001() +{ + IMAGE_LOGI("NV21ToRGB565FuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::RGB_565; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToRGB565FuzzTest001: end"); +} + +void NV21ToRGB565FuzzTest002() +{ + IMAGE_LOGI("NV21ToRGB565FuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::RGB_565; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToRGB565FuzzTest002: end"); +} + +void NV21ToNV12FuzzTest001() +{ + IMAGE_LOGI("NV21ToNV12FuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::NV12; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToNV12FuzzTest001: end"); +} + +void NV21ToNV12FuzzTest002() +{ + IMAGE_LOGI("NV21ToNV12FuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::NV12; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToNV12FuzzTest002: end"); +} + +void NV12ToNV21FuzzTest001() +{ + IMAGE_LOGI("NV12ToNV21FuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::NV21; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToNV21FuzzTest001: end"); +} + +void NV12ToNV21FuzzTest002() +{ + IMAGE_LOGI("NV12ToNV21FuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::NV21; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToNV21FuzzTest002: end"); +} + +void NV12ToRGB565FuzzTest001() +{ + IMAGE_LOGI("NV12ToRGB565FuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::RGB_565; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToRGB565FuzzTest001: end"); +} + +void NV12ToRGB565FuzzTest002() +{ + IMAGE_LOGI("NV12ToRGB565FuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::RGB_565; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToRGB565FuzzTest002: end"); +} + +void NV12ToRGBAFuzzTest001() +{ + IMAGE_LOGI("NV12ToRGBAFuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::RGBA_8888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToRGBAFuzzTest001: end"); +} + +void NV12ToRGBAFuzzTest002() +{ + IMAGE_LOGI("NV12ToRGBAFuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::RGBA_8888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToRGBAFuzzTest002: end"); +} + +void NV12ToBGRAFuzzTest001() +{ + IMAGE_LOGI("NV12ToBGRAFuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::BGRA_8888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToBGRAFuzzTest001: end"); +} + +void NV12ToBGRAFuzzTest002() +{ + IMAGE_LOGI("NV12ToBGRAFuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::BGRA_8888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToBGRAFuzzTest002: end"); +} + +void NV12ToRGBFuzzTest001() +{ + IMAGE_LOGI("NV12ToRGBFuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::RGB_888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToRGBFuzzTest001: end"); +} + +void NV12ToRGBFuzzTest002() +{ + IMAGE_LOGI("NV12ToRGBFuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::RGB_888; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToRGBFuzzTest002: end"); +} + +void NV21ToNV12P010FuzzTest001() +{ + IMAGE_LOGI("NV21ToNV12P010FuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::YCBCR_P010; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToNV12P010FuzzTest001: end"); +} + +void NV21ToNV12P010FuzzTest002() +{ + IMAGE_LOGI("NV21ToNV12P010FuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::YCBCR_P010; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToNV12P010FuzzTest002: end"); +} + +void NV12ToNV12P010FuzzTest001() +{ + IMAGE_LOGI("NV12ToNV12P010FuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::YCBCR_P010; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToNV12P010FuzzTest001: end"); +} + +void NV12ToNV12P010FuzzTest002() +{ + IMAGE_LOGI("NV12ToNV12P010FuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::YCBCR_P010; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToNV12P010FuzzTest002: end"); +} + +void NV21ToRGBAF16FuzzTest001() +{ + IMAGE_LOGI("NV21ToRGBAF16FuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::RGBA_F16; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToRGBAF16FuzzTest001: end"); +} + +void NV21ToRGBAF16FuzzTest002() +{ + IMAGE_LOGI("NV21ToRGBAF16FuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::RGBA_F16; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToRGBAF16FuzzTest002: end"); +} + +void NV12ToRGBAF16FuzzTest001() +{ + IMAGE_LOGI("NV12ToRGBAF16FuzzTest001: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::RGBA_F16; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToRGBAF16FuzzTest001: end"); +} + +void NV12ToRGBAF16FuzzTest002() +{ + IMAGE_LOGI("NV12ToRGBAF16FuzzTest002: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::RGBA_F16; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToRGBAF16FuzzTest002: end"); +} + +void NV21ToNV21P010FuzzTest003() +{ + IMAGE_LOGI("NV21ToNV21P010FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::YCRCB_P010; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToNV21P010FuzzTest003: end"); +} + +void NV12ToNV21P010FuzzTest003() +{ + IMAGE_LOGI("NV12ToNV21P010FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::YCRCB_P010; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToNV21P010FuzzTest003: end"); +} + +void NV12ToRGBA1010102FuzzTest003() +{ + IMAGE_LOGI("NV12ToRGBA1010102FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::NV12; + PixelFormat destFormat = PixelFormat::RGBA_1010102; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV12ToRGBA1010102FuzzTest003: end"); +} + +void NV21ToRGBA1010102FuzzTest003() +{ + IMAGE_LOGI("NV21ToRGBA1010102FuzzTest003: start"); + PixelFormat srcFormat = PixelFormat::NV21; + PixelFormat destFormat = PixelFormat::RGBA_1010102; + YuvConvertToRgb(srcFormat, destFormat); + IMAGE_LOGI("NV21ToRGBA1010102FuzzTest003: end"); +} + +void YuvToRgbFuzzTest001() +{ + IMAGE_LOGI("YuvToRgbFuzzTest001: start"); + NV21ToRGBFuzzTest001(); + NV21ToRGBFuzzTest002(); + NV21ToRGBAFuzzTest001(); + NV21ToRGBAFuzzTest002(); + NV21ToBGRAFuzzTest001(); + NV21ToBGRAFuzzTest002(); + NV21ToRGB565FuzzTest001(); + NV21ToRGB565FuzzTest002(); + NV21ToNV12FuzzTest001(); + NV21ToNV12FuzzTest002(); + NV12ToNV21FuzzTest001(); + NV12ToNV21FuzzTest002(); + NV12ToRGB565FuzzTest001(); + NV12ToRGB565FuzzTest002(); + NV12ToRGBAFuzzTest001(); + NV12ToRGBAFuzzTest002(); + NV12ToBGRAFuzzTest001(); + NV12ToBGRAFuzzTest002(); + NV12ToRGBFuzzTest001(); + NV12ToRGBFuzzTest002(); + NV21ToNV12P010FuzzTest001(); + NV21ToNV12P010FuzzTest002(); + NV12ToNV12P010FuzzTest001(); + NV12ToNV12P010FuzzTest002(); + NV21ToRGBAF16FuzzTest001(); + NV21ToRGBAF16FuzzTest002(); + NV12ToRGBAF16FuzzTest001(); + NV12ToRGBAF16FuzzTest002(); + NV21ToNV21P010FuzzTest003(); + NV12ToNV21P010FuzzTest003(); + NV12ToRGBA1010102FuzzTest003(); + NV21ToRGBA1010102FuzzTest003(); + IMAGE_LOGI("YuvToRgbFuzzTest001: end"); +} + +/* + * test pixelmap IPC interface + */ +bool g_pixelMapIpcTest(std::unique_ptr &pixelMap) +{ + if (!pixelMap) { + return false; + } + // test parcel pixelmap + MessageParcel parcel; + pixelMap->SetMemoryName("MarshallingPixelMap"); + if (!pixelMap->Marshalling(parcel)) { + IMAGE_LOGI("g_pixelMapIpcTest Marshalling failed id: %{public}d, isUnmap: %{public}d", + pixelMap->GetUniqueId(), pixelMap->IsUnMap()); + return false; + } + Media::PixelMap* unmarshallingPixelMap = Media::PixelMap::Unmarshalling(parcel); + if (!unmarshallingPixelMap) { + return false; + } + unmarshallingPixelMap->SetMemoryName("unmarshallingPixelMap"); + IMAGE_LOGI("g_pixelMapIpcTest unmarshallingPixelMap failed id: %{public}d, isUnmap: %{public}d", + unmarshallingPixelMap->GetUniqueId(), unmarshallingPixelMap->IsUnMap()); + unmarshallingPixelMap->FreePixelMap(); + delete unmarshallingPixelMap; + unmarshallingPixelMap = nullptr; + return true; +} + +std::unique_ptr GetYuvPixelMap(PixelFormat &srcFormat) +{ + IMAGE_LOGI("GetYuvPixelMap: start"); + uint32_t errorCode = 0; + SourceOptions opts; + opts.formatHint = "image/jpeg"; + std::string jpgPath = IMAGE_INPUT_JPG_PATH1; + std::unique_ptr rImageSource = ImageSource::CreateImageSource(jpgPath, opts, errorCode); + if (errorCode != SUCCESS || rImageSource.get() == nullptr) { + IMAGE_LOGE("GetYuvPixelMap: CreateImageSource fail"); + return nullptr; + } + DecodeOptions decodeOpts; + decodeOpts.desiredPixelFormat = srcFormat; + std::unique_ptr srcPixelMap = rImageSource->CreatePixelMap(decodeOpts, errorCode); + if (errorCode != SUCCESS || srcPixelMap.get() == nullptr) { + IMAGE_LOGE("GetYuvPixelMap: CreatePixelMap fail"); + return nullptr; + } + return srcPixelMap; +} + +void NV21PixelMapIPCTest001() +{ + PixelFormat srcFormat = PixelFormat::NV21; + std::unique_ptr yuvPixelMap = GetYuvPixelMap(srcFormat); + g_pixelMapIpcTest(yuvPixelMap); +} + +void NV12PixelMapIPCTest001() +{ + PixelFormat srcFormat = PixelFormat::NV12; + std::unique_ptr yuvPixelMap = GetYuvPixelMap(srcFormat); + g_pixelMapIpcTest(yuvPixelMap); +} + +void YuvPixelMapIPCFuzzTest001() +{ + NV21PixelMapIPCTest001(); + NV12PixelMapIPCTest001(); +} + +} // namespace Media +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + static const std::string pathName = "/data/local/tmp/test.jpg"; + int fd = open(pathName.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (write(fd, data, size) != (ssize_t)size) { + close(fd); + IMAGE_LOGE("Fuzzer copy data fail"); + return 0; + } + close(fd); + OHOS::Media::YuvToRgbFuzzTest001(); + OHOS::Media::YuvPixelMapIPCFuzzTest001(); + return 0; +} \ No newline at end of file diff --git a/frameworks/innerkitsimpl/test/unittest/image_utils_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_utils_test.cpp index bf3ca841ecb99051dc75832e45ae8cb34a2bf54e..3f7229a402f7757d682b1ef314101af01854c81f 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_utils_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_utils_test.cpp @@ -850,8 +850,6 @@ HWTEST_F(ImageUtilsTest, DumpPixelMapTest001, TestSize.Level3) std::string customFileName = "test"; uint64_t imageId = 0; Media::ImageUtils::DumpPixelMap(pixelMap.get(), customFileName, imageId); - EXPECT_EQ(customFileName, "test"); - EXPECT_EQ(imageId, 0); GTEST_LOG_(INFO) << "ImageUtilsTest: DumpPixelMapTest001 end"; } }