From 801e6dbe4f65462d676b81102f88a57a9234fde4 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Mon, 28 Jul 2025 10:22:51 +0800 Subject: [PATCH 01/12] fix bug into ffmpeg Signed-off-by: fanzhihao8 --- .../src/image_format_convert_utils.cpp | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index f129ade2f..d9d4c42cd 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -1148,9 +1148,29 @@ static bool YuvToYuv(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelF yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0 || destInfo.bufferSize == 0) { return false; } - SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight}; - srcParam.format = srcFormat; + int32_t copyWidth = yDInfo.yWidth; + int32_t copyHeight = yDInfo.yHeight; + SrcConvertParam srcParam; srcParam.buffer = srcBuffer; + std::unique_ptr copySrcBuffer; + if (yDInfo.yWidth % EVEN_ALIGNMENT != 0 || yDInfo.yHeight % EVEN_ALIGNMENT != 0) { + if (!ImageUtils::GetAlignedNumber(copyWidth, EVEN_ALIGNMENT) || + !ImageUtils::GetAlignedNumber(copyHeight, EVEN_ALIGNMENT)) { + return false; + } + int32_t copySrcLen = copyWidth * copyHeight * ImageUtils::GetPixelBytes(srcFormat); + int32_t yDInfoLen = yDInfo.yWidth * yDInfo.yHeight * ImageUtils::GetPixelBytes(srcFormat); + copySrcBuffer = std::make_unique(copySrcLen); + if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), yDInfoLen, srcBuffer, yDInfoLen)) { + IMAGE_LOGE("alloc memory or memcpy_s failed!"); + return false; + } + srcParam.buffer = copySrcBuffer.get(); + } + srcParam.width = static_cast(copyWidth); + srcParam.height = static_cast(copyHeight); + srcParam.format = srcFormat; + DestConvertParam destParam = {destInfo.width, destInfo.height}; destParam.format = destFormat; @@ -1173,9 +1193,28 @@ static bool YuvToRGB(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelF yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0 || destInfo.bufferSize == 0) { return false; } - SrcConvertParam srcParam = {yDInfo.yWidth, yDInfo.yHeight}; - srcParam.format = srcFormat; + int32_t copyWidth = yDInfo.yWidth; + int32_t copyHeight = yDInfo.yHeight; + SrcConvertParam srcParam; srcParam.buffer = srcBuffer; + std::unique_ptr copySrcBuffer; + if (yDInfo.yWidth % EVEN_ALIGNMENT != 0 || yDInfo.yHeight % EVEN_ALIGNMENT != 0) { + if (!ImageUtils::GetAlignedNumber(copyWidth, EVEN_ALIGNMENT) || + !ImageUtils::GetAlignedNumber(copyHeight, EVEN_ALIGNMENT)) { + return false; + } + int32_t copySrcLen = copyWidth * copyHeight * ImageUtils::GetPixelBytes(srcFormat); + int32_t yDInfoLen = yDInfo.yWidth * yDInfo.yHeight * ImageUtils::GetPixelBytes(srcFormat); + copySrcBuffer = std::make_unique(copySrcLen); + if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), yDInfoLen, srcBuffer, yDInfoLen)) { + IMAGE_LOGE("alloc memory or memcpy_s failed!"); + return false; + } + srcParam.buffer = copySrcBuffer.get(); + } + srcParam.width = static_cast(copyWidth); + srcParam.height = static_cast(copyHeight); + srcParam.format = srcFormat; DestConvertParam destParam = {destInfo.width, destInfo.height}; destParam.format = destFormat; @@ -1190,7 +1229,6 @@ static bool YuvToRGB(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelF } return true; } - static bool RGBToYuv(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo, PixelFormat srcFormat, DestConvertInfo &destInfo, PixelFormat destFormat) { -- Gitee From cabc74aeef68f3dfb27fe26ae3f4351edcc47d27 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Mon, 28 Jul 2025 12:58:59 +0800 Subject: [PATCH 02/12] fix bug into ffmpeg Signed-off-by: fanzhihao8 --- .../innerkitsimpl/converter/src/image_format_convert_utils.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index d9d4c42cd..916d37d75 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -1171,7 +1171,6 @@ static bool YuvToYuv(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelF srcParam.height = static_cast(copyHeight); srcParam.format = srcFormat; - DestConvertParam destParam = {destInfo.width, destInfo.height}; destParam.format = destFormat; -- Gitee From 01c942fe377384dba2a4a2651f9ed5773b1fdf04 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Mon, 28 Jul 2025 12:59:45 +0800 Subject: [PATCH 03/12] fix bug into ffmpeg Signed-off-by: fanzhihao8 --- .../innerkitsimpl/converter/src/image_format_convert_utils.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index 916d37d75..602eae869 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -1228,6 +1228,7 @@ static bool YuvToRGB(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelF } return true; } + static bool RGBToYuv(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo, PixelFormat srcFormat, DestConvertInfo &destInfo, PixelFormat destFormat) { -- Gitee From 3d9b91a3faa5d80e4bed94b47432b8f8257ebd80 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Mon, 28 Jul 2025 16:43:55 +0800 Subject: [PATCH 04/12] fix bug and check Signed-off-by: fanzhihao8 --- .../src/image_format_convert_utils.cpp | 106 +++++++++--------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index 602eae869..97cab5f8f 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -1141,27 +1141,30 @@ static bool YuvToYuvParam(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam, return true; } -static bool YuvToYuv(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat, - DestConvertInfo &destInfo, PixelFormat destFormat) -{ - if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 || - yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0 || destInfo.bufferSize == 0) { +static bool ProcessSrcParamCore(int32_t srcWidth, int32_t srcHeight, PixelFormat srcFormat, + const uint8_t* srcBuffer, SrcConvertParam& srcParam, + std::unique_ptr& copySrcBuffer) { + if (srcWidth <= 0 || srcHeight <= 0) { + IMAGE_LOGE("Invalid src width(%{public}d) or height(%{public}d)", srcWidth, srcHeight); return false; } - int32_t copyWidth = yDInfo.yWidth; - int32_t copyHeight = yDInfo.yHeight; - SrcConvertParam srcParam; srcParam.buffer = srcBuffer; - std::unique_ptr copySrcBuffer; - if (yDInfo.yWidth % EVEN_ALIGNMENT != 0 || yDInfo.yHeight % EVEN_ALIGNMENT != 0) { + int32_t copyWidth = srcWidth; + int32_t copyHeight = srcHeight; + + if (srcWidth % EVEN_ALIGNMENT != 0 || srcHeight % EVEN_ALIGNMENT != 0) { if (!ImageUtils::GetAlignedNumber(copyWidth, EVEN_ALIGNMENT) || !ImageUtils::GetAlignedNumber(copyHeight, EVEN_ALIGNMENT)) { + IMAGE_LOGE("Failed to get aligned width/height"); return false; } - int32_t copySrcLen = copyWidth * copyHeight * ImageUtils::GetPixelBytes(srcFormat); - int32_t yDInfoLen = yDInfo.yWidth * yDInfo.yHeight * ImageUtils::GetPixelBytes(srcFormat); - copySrcBuffer = std::make_unique(copySrcLen); - if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), yDInfoLen, srcBuffer, yDInfoLen)) { + + int32_t pixelBytes = ImageUtils::GetPixelBytes(srcFormat); + int32_t srcDataLen = srcWidth * srcHeight * pixelBytes; + int32_t alignedBufferLen = copyWidth * copyHeight * pixelBytes; + + copySrcBuffer = std::make_unique(alignedBufferLen); + if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), srcDataLen, srcBuffer, srcDataLen)) { IMAGE_LOGE("alloc memory or memcpy_s failed!"); return false; } @@ -1170,6 +1173,37 @@ static bool YuvToYuv(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelF srcParam.width = static_cast(copyWidth); srcParam.height = static_cast(copyHeight); srcParam.format = srcFormat; + return true; +} + +static bool ProcessSrcParam(const YUVDataInfo& yDInfo, PixelFormat srcFormat, const uint8_t* srcBuffer, + SrcConvertParam& srcParam, std::unique_ptr& copySrcBuffer) { + return ProcessSrcParamCore(static_cast(yDInfo.yWidth), static_cast(yDInfo.yHeight), + srcFormat, srcBuffer, srcParam, copySrcBuffer); +} + +static bool ProcessSrcParam(const RGBDataInfo& rgbInfo, PixelFormat srcFormat, const uint8_t* srcBuffer, + SrcConvertParam& srcParam, std::unique_ptr& copySrcBuffer) { + if (rgbInfo.width < 0 || rgbInfo.height < 0) { + IMAGE_LOGE("RGB width(%{public}d) or height(%{public}d) is negative", rgbInfo.width, rgbInfo.height); + return false; + } + return ProcessSrcParamCore(rgbInfo.width, rgbInfo.height, srcFormat, srcBuffer, srcParam, copySrcBuffer); +} + +static bool YuvToYuv(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat, + DestConvertInfo &destInfo, PixelFormat destFormat) +{ + if (srcBuffer == nullptr || destInfo.buffer == nullptr || yDInfo.yWidth == 0 || yDInfo.yHeight == 0 || + yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0 || destInfo.bufferSize == 0) { + return false; + } + SrcConvertParam srcParam; + std::unique_ptr copySrcBuffer; + if (!ProcessSrcParam(yDInfo, srcFormat, srcBuffer, srcParam, copySrcBuffer)) { + IMAGE_LOGE("Process src param failed for YuvToYuv"); + return false; + } DestConvertParam destParam = {destInfo.width, destInfo.height}; destParam.format = destFormat; @@ -1192,28 +1226,12 @@ static bool YuvToRGB(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelF yDInfo.uvWidth == 0 || yDInfo.uvHeight == 0 || destInfo.bufferSize == 0) { return false; } - int32_t copyWidth = yDInfo.yWidth; - int32_t copyHeight = yDInfo.yHeight; SrcConvertParam srcParam; - srcParam.buffer = srcBuffer; std::unique_ptr copySrcBuffer; - if (yDInfo.yWidth % EVEN_ALIGNMENT != 0 || yDInfo.yHeight % EVEN_ALIGNMENT != 0) { - if (!ImageUtils::GetAlignedNumber(copyWidth, EVEN_ALIGNMENT) || - !ImageUtils::GetAlignedNumber(copyHeight, EVEN_ALIGNMENT)) { - return false; - } - int32_t copySrcLen = copyWidth * copyHeight * ImageUtils::GetPixelBytes(srcFormat); - int32_t yDInfoLen = yDInfo.yWidth * yDInfo.yHeight * ImageUtils::GetPixelBytes(srcFormat); - copySrcBuffer = std::make_unique(copySrcLen); - if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), yDInfoLen, srcBuffer, yDInfoLen)) { - IMAGE_LOGE("alloc memory or memcpy_s failed!"); - return false; - } - srcParam.buffer = copySrcBuffer.get(); + if (!ProcessSrcParam(yDInfo, srcFormat, srcBuffer, srcParam, copySrcBuffer)) { + IMAGE_LOGE("Process src param failed for YuvToRGB"); + return false; } - srcParam.width = static_cast(copyWidth); - srcParam.height = static_cast(copyHeight); - srcParam.format = srcFormat; DestConvertParam destParam = {destInfo.width, destInfo.height}; destParam.format = destFormat; @@ -1236,28 +1254,12 @@ static bool RGBToYuv(const uint8_t *srcBuffer, const RGBDataInfo &rgbInfo, Pixel destInfo.bufferSize == 0) { return false; } - int32_t copyWidth = rgbInfo.width; - int32_t copyHeight = rgbInfo.height; SrcConvertParam srcParam; - srcParam.buffer = srcBuffer; std::unique_ptr copySrcBuffer; - if (rgbInfo.width % EVEN_ALIGNMENT != 0 || rgbInfo.height % EVEN_ALIGNMENT != 0) { - if (!ImageUtils::GetAlignedNumber(copyWidth, EVEN_ALIGNMENT) || - !ImageUtils::GetAlignedNumber(copyHeight, EVEN_ALIGNMENT)) { - return false; - } - int32_t copySrcLen = copyWidth * copyHeight * ImageUtils::GetPixelBytes(srcFormat); - int32_t rgbInfoLen = rgbInfo.width * rgbInfo.height * ImageUtils::GetPixelBytes(srcFormat); - copySrcBuffer = std::make_unique(copySrcLen); - if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), rgbInfoLen, srcBuffer, rgbInfoLen)) { - IMAGE_LOGE("alloc memory or memcpy_s failed!"); - return false; - } - srcParam.buffer = copySrcBuffer.get(); + if (!ProcessSrcParam(rgbInfo, srcFormat, srcBuffer, srcParam, copySrcBuffer)) { + IMAGE_LOGE("Process src param failed for RGBToYuv"); + return false; } - srcParam.width = static_cast(copyWidth); - srcParam.height = static_cast(copyHeight); - srcParam.format = srcFormat; DestConvertParam destParam = {destInfo.width, destInfo.height}; destParam.format = destFormat; -- Gitee From ff2c05be185c3965e99921d43c53c681181b745e Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Mon, 28 Jul 2025 17:12:51 +0800 Subject: [PATCH 05/12] fix bug and check Signed-off-by: fanzhihao8 --- .../src/image_format_convert_utils.cpp | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index 97cab5f8f..3440b8ab6 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -1141,26 +1141,26 @@ static bool YuvToYuvParam(const YUVDataInfo &yDInfo, SrcConvertParam &srcParam, return true; } -static bool ProcessSrcParamCore(int32_t srcWidth, int32_t srcHeight, PixelFormat srcFormat, - const uint8_t* srcBuffer, SrcConvertParam& srcParam, - std::unique_ptr& copySrcBuffer) { - if (srcWidth <= 0 || srcHeight <= 0) { - IMAGE_LOGE("Invalid src width(%{public}d) or height(%{public}d)", srcWidth, srcHeight); +static bool ProcessSrcParamCore(const SrcDataInfo& srcData, SrcConvertParam& srcParam, + std::unique_ptr& copySrcBuffer) +{ + if (srcData.width <= 0 || srcData.height <= 0) { + IMAGE_LOGE("Invalid src width(%{public}d) or height(%{public}d)", srcData.width, srcData.height); return false; } - srcParam.buffer = srcBuffer; - int32_t copyWidth = srcWidth; - int32_t copyHeight = srcHeight; + srcParam.buffer = srcData.buffer; + int32_t copyWidth = srcData.width; + int32_t copyHeight = srcData.height; - if (srcWidth % EVEN_ALIGNMENT != 0 || srcHeight % EVEN_ALIGNMENT != 0) { + if (srcData.width % EVEN_ALIGNMENT != 0 || srcData.height % EVEN_ALIGNMENT != 0) { if (!ImageUtils::GetAlignedNumber(copyWidth, EVEN_ALIGNMENT) || !ImageUtils::GetAlignedNumber(copyHeight, EVEN_ALIGNMENT)) { IMAGE_LOGE("Failed to get aligned width/height"); return false; } - int32_t pixelBytes = ImageUtils::GetPixelBytes(srcFormat); - int32_t srcDataLen = srcWidth * srcHeight * pixelBytes; + int32_t pixelBytes = ImageUtils::GetPixelBytes(srcData.format); + int32_t srcDataLen = srcData.width * srcData.height * pixelBytes; int32_t alignedBufferLen = copyWidth * copyHeight * pixelBytes; copySrcBuffer = std::make_unique(alignedBufferLen); @@ -1172,24 +1172,36 @@ static bool ProcessSrcParamCore(int32_t srcWidth, int32_t srcHeight, PixelFormat } srcParam.width = static_cast(copyWidth); srcParam.height = static_cast(copyHeight); - srcParam.format = srcFormat; + srcParam.format = srcData.format; return true; } static bool ProcessSrcParam(const YUVDataInfo& yDInfo, PixelFormat srcFormat, const uint8_t* srcBuffer, - SrcConvertParam& srcParam, std::unique_ptr& copySrcBuffer) { - return ProcessSrcParamCore(static_cast(yDInfo.yWidth), static_cast(yDInfo.yHeight), - srcFormat, srcBuffer, srcParam, copySrcBuffer); + SrcConvertParam& srcParam, std::unique_ptr& copySrcBuffer) +{ + SrcDataInfo srcData = { + static_cast(yDInfo.yWidth), + static_cast(yDInfo.yHeight), + srcFormat, + srcBuffer + }; + return ProcessSrcParamCore(srcData, srcParam, copySrcBuffer); } static bool ProcessSrcParam(const RGBDataInfo& rgbInfo, PixelFormat srcFormat, const uint8_t* srcBuffer, - SrcConvertParam& srcParam, std::unique_ptr& copySrcBuffer) { + SrcConvertParam& srcParam, std::unique_ptr& copySrcBuffer) +{ if (rgbInfo.width < 0 || rgbInfo.height < 0) { IMAGE_LOGE("RGB width(%{public}d) or height(%{public}d) is negative", rgbInfo.width, rgbInfo.height); return false; } - return ProcessSrcParamCore(rgbInfo.width, rgbInfo.height, srcFormat, srcBuffer, srcParam, copySrcBuffer); -} + SrcDataInfo srcData = { + rgbInfo.width, + rgbInfo.height, + srcFormat, + srcBuffer + }; + return ProcessSrcParamCore(srcData, srcParam, copySrcBuffer);} static bool YuvToYuv(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat, DestConvertInfo &destInfo, PixelFormat destFormat) -- Gitee From c17bb3f7852a39641b67a2fdc90ecf9184335c23 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Mon, 28 Jul 2025 18:31:38 +0800 Subject: [PATCH 06/12] fix bug and check Signed-off-by: fanzhihao8 --- .../converter/src/image_format_convert_utils.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index 3440b8ab6..ada5c20e8 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -47,6 +47,12 @@ namespace { constexpr uint32_t STRIDES_PER_PLANE = 8; constexpr int32_t PIXEL_MAP_MAX_RAM_SIZE = 600 * 1024 * 1024; constexpr uint32_t EVEN_ALIGNMENT = 2; + struct SrcDataInfo { + int32_t srcWidth; + int32_t srcHeight; + PixelFormat srcFormat; + const uint8_t* srcBuffer; + }; } #undef LOG_TAG @@ -1152,7 +1158,7 @@ static bool ProcessSrcParamCore(const SrcDataInfo& srcData, SrcConvertParam& src int32_t copyWidth = srcData.width; int32_t copyHeight = srcData.height; - if (srcData.width % EVEN_ALIGNMENT != 0 || srcData.height % EVEN_ALIGNMENT != 0) { + if (srcData.width % EVEN_ALIGNMENT != 0 || srcData.height % EVEN_ALIGNMENT != 0) { if (!ImageUtils::GetAlignedNumber(copyWidth, EVEN_ALIGNMENT) || !ImageUtils::GetAlignedNumber(copyHeight, EVEN_ALIGNMENT)) { IMAGE_LOGE("Failed to get aligned width/height"); @@ -1164,7 +1170,7 @@ static bool ProcessSrcParamCore(const SrcDataInfo& srcData, SrcConvertParam& src int32_t alignedBufferLen = copyWidth * copyHeight * pixelBytes; copySrcBuffer = std::make_unique(alignedBufferLen); - if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), srcDataLen, srcBuffer, srcDataLen)) { + if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), srcDataLen, srcData.buffer, srcDataLen)) { IMAGE_LOGE("alloc memory or memcpy_s failed!"); return false; } @@ -1201,7 +1207,8 @@ static bool ProcessSrcParam(const RGBDataInfo& rgbInfo, PixelFormat srcFormat, c srcFormat, srcBuffer }; - return ProcessSrcParamCore(srcData, srcParam, copySrcBuffer);} + return ProcessSrcParamCore(srcData, srcParam, copySrcBuffer); +} static bool YuvToYuv(const uint8_t *srcBuffer, const YUVDataInfo &yDInfo, PixelFormat srcFormat, DestConvertInfo &destInfo, PixelFormat destFormat) -- Gitee From 9edb04cda6616366b9790307459f391945ed8ab7 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Mon, 28 Jul 2025 19:27:11 +0800 Subject: [PATCH 07/12] fix bug and check Signed-off-by: fanzhihao8 --- .../converter/src/image_format_convert_utils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index ada5c20e8..58cc16162 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -48,10 +48,10 @@ namespace { constexpr int32_t PIXEL_MAP_MAX_RAM_SIZE = 600 * 1024 * 1024; constexpr uint32_t EVEN_ALIGNMENT = 2; struct SrcDataInfo { - int32_t srcWidth; - int32_t srcHeight; - PixelFormat srcFormat; - const uint8_t* srcBuffer; + int32_t width; + int32_t height; + PixelFormat format; + const uint8_t* buffer; }; } -- Gitee From 1e50c80ea46408af074b37f74f3142e2054cf1e7 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Mon, 28 Jul 2025 19:55:41 +0800 Subject: [PATCH 08/12] fix bug and check Signed-off-by: fanzhihao8 --- .../converter/src/image_format_convert_utils.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index 58cc16162..a41854c1b 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -47,18 +47,18 @@ namespace { constexpr uint32_t STRIDES_PER_PLANE = 8; constexpr int32_t PIXEL_MAP_MAX_RAM_SIZE = 600 * 1024 * 1024; constexpr uint32_t EVEN_ALIGNMENT = 2; - struct SrcDataInfo { - int32_t width; - int32_t height; - PixelFormat format; - const uint8_t* buffer; - }; } #undef LOG_TAG #define LOG_TAG "ImageFormatConvert" namespace OHOS { namespace Media { +struct SrcDataInfo { + int32_t width; + int32_t height; + PixelFormat format; + const uint8_t* buffer; +}; static AVPixelFormat findPixelFormat(PixelFormat format) { auto formatSearch = PixelConvertAdapter::FFMPEG_PIXEL_FORMAT_MAP.find(format); -- Gitee From 20ba39492f92cdff8d9cf14fd56a18f8372b767b Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Tue, 29 Jul 2025 12:08:23 +0800 Subject: [PATCH 09/12] fix bug and check Signed-off-by: fanzhihao8 --- .../src/image_format_convert_utils.cpp | 4 ---- .../image_format_convert_fail_test.cpp | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index a41854c1b..44a4b817e 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -1197,10 +1197,6 @@ static bool ProcessSrcParam(const YUVDataInfo& yDInfo, PixelFormat srcFormat, co static bool ProcessSrcParam(const RGBDataInfo& rgbInfo, PixelFormat srcFormat, const uint8_t* srcBuffer, SrcConvertParam& srcParam, std::unique_ptr& copySrcBuffer) { - if (rgbInfo.width < 0 || rgbInfo.height < 0) { - IMAGE_LOGE("RGB width(%{public}d) or height(%{public}d) is negative", rgbInfo.width, rgbInfo.height); - return false; - } SrcDataInfo srcData = { rgbInfo.width, rgbInfo.height, diff --git a/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp index c2cfc130f..88c156616 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp @@ -345,5 +345,29 @@ HWTEST_F(ImageFormatConvertFailTest, RGB1010102ConvertToYUVP010, TestSize.Level1 ConvertFunction cvtFunc = ImageFormatConvert::GetConvertFuncByFormat(srcFormat, destFormat); EXPECT_EQ(cvtFunc(srcBuffer, rgbInfo, destInfo, colorspace), false); } + +/** + * @tc.name: RGBF16ConvertToYUV + * @tc.desc: Test RGBF16ConvertToYUV with invalid info. + * @tc.type: FUNC + */ +HWTEST_F(ImageFormatConvertFailTest, RGBF16ConvertToYUV, TestSize.Level1) +{ + PixelFormat srcFormat = PixelFormat::RGBF16; + PixelFormat destFormat = PixelFormat::NV21; + uint8_t srcBuffer[LENGTH] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; + RGBDataInfo rgbInfo; + rgbInfo.width = -1; + rgbInfo.height = -1; + ColorSpace colorspace = ColorSpace::UNKNOWN; + DestConvertInfo destInfo; + destInfo.width = 1; + destInfo.height = 1; + destInfo.buffer = new uint8_t[8]; + destInfo.bufferSize = 16; + + ConvertFunction cvtFunc = ImageFormatConvert::GetConvertFuncByFormat(srcFormat, destFormat); + EXPECT_EQ(cvtFunc(srcBuffer, rgbInfo, destInfo, colorspace), false); +} } // namespace Media } // namespace OHOS \ No newline at end of file -- Gitee From 9b61203e78bea1e61cb05b98aa5bac4396bf829a Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Tue, 29 Jul 2025 12:47:06 +0800 Subject: [PATCH 10/12] fix bug and check Signed-off-by: fanzhihao8 --- .../test/unittest/image_format_convert_fail_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp index 88c156616..2c493ac10 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp @@ -347,13 +347,13 @@ HWTEST_F(ImageFormatConvertFailTest, RGB1010102ConvertToYUVP010, TestSize.Level1 } /** - * @tc.name: RGBF16ConvertToYUV - * @tc.desc: Test RGBF16ConvertToYUV with invalid info. + * @tc.name: RGBAF16ConvertToYUV + * @tc.desc: Test RGBAF16ConvertToYUV with invalid info. * @tc.type: FUNC */ HWTEST_F(ImageFormatConvertFailTest, RGBF16ConvertToYUV, TestSize.Level1) { - PixelFormat srcFormat = PixelFormat::RGBF16; + PixelFormat srcFormat = PixelFormat::RGBA_F16; PixelFormat destFormat = PixelFormat::NV21; uint8_t srcBuffer[LENGTH] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; RGBDataInfo rgbInfo; -- Gitee From 295fce5414a40a0297461fbac1603a4e2ff7f6fc Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Tue, 29 Jul 2025 12:48:04 +0800 Subject: [PATCH 11/12] fix bug and check Signed-off-by: fanzhihao8 --- .../test/unittest/image_format_convert_fail_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp b/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp index 2c493ac10..99516a5a7 100644 --- a/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp +++ b/frameworks/innerkitsimpl/test/unittest/image_format_convert_fail_test.cpp @@ -351,7 +351,7 @@ HWTEST_F(ImageFormatConvertFailTest, RGB1010102ConvertToYUVP010, TestSize.Level1 * @tc.desc: Test RGBAF16ConvertToYUV with invalid info. * @tc.type: FUNC */ -HWTEST_F(ImageFormatConvertFailTest, RGBF16ConvertToYUV, TestSize.Level1) +HWTEST_F(ImageFormatConvertFailTest, RGBAF16ConvertToYUV, TestSize.Level1) { PixelFormat srcFormat = PixelFormat::RGBA_F16; PixelFormat destFormat = PixelFormat::NV21; -- Gitee From 747be25d80a111e36942d55cd699226689aca594 Mon Sep 17 00:00:00 2001 From: fanzhihao8 Date: Tue, 5 Aug 2025 16:18:22 +0800 Subject: [PATCH 12/12] fix before into ffmpeg Signed-off-by: fanzhihao8 --- .../converter/src/image_format_convert_utils.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp index 44a4b817e..fe3ab7f66 100644 --- a/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp +++ b/frameworks/innerkitsimpl/converter/src/image_format_convert_utils.cpp @@ -1166,11 +1166,15 @@ static bool ProcessSrcParamCore(const SrcDataInfo& srcData, SrcConvertParam& src } int32_t pixelBytes = ImageUtils::GetPixelBytes(srcData.format); + if (pixelBytes == 0) { + IMAGE_LOGE("Invalid pixel bytes(%{public}d) for format", pixelBytes); + return false; + } int32_t srcDataLen = srcData.width * srcData.height * pixelBytes; - int32_t alignedBufferLen = copyWidth * copyHeight * pixelBytes; + int32_t copySrcLen = copyWidth * copyHeight * pixelBytes; - copySrcBuffer = std::make_unique(alignedBufferLen); - if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), srcDataLen, srcData.buffer, srcDataLen)) { + copySrcBuffer = std::make_unique(copySrcLen); + if (copySrcBuffer == nullptr || EOK != memcpy_s(copySrcBuffer.get(), copySrcLen, srcData.buffer, srcDataLen)) { IMAGE_LOGE("alloc memory or memcpy_s failed!"); return false; } -- Gitee