From 2cc1c44a95e7cad8a121de6cb7133c5f705774a8 Mon Sep 17 00:00:00 2001 From: yaozhupeng Date: Sat, 2 Aug 2025 20:00:47 +0800 Subject: [PATCH] add ipc limit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yaozhupeng Signed-off-by: 陈乔异 --- .../innerkitsimpl/utils/src/image_utils.cpp | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/frameworks/innerkitsimpl/utils/src/image_utils.cpp b/frameworks/innerkitsimpl/utils/src/image_utils.cpp index a62df6530..bc5bd98c3 100644 --- a/frameworks/innerkitsimpl/utils/src/image_utils.cpp +++ b/frameworks/innerkitsimpl/utils/src/image_utils.cpp @@ -1257,5 +1257,62 @@ void ImageUtils::SetReuseContextBuffer(ImagePlugin::DecodeContext& context, context.pixelsBuffer.bufferSize = count; context.pixelsBuffer.context = fd; } + +bool ImageUtils::CheckRowDataSizeIsVaild(int32_t &rowDataSize, ImageInfo &imgInfo) +{ + int32_t bytesPerPixel = ImageUtils::GetPixelBytes(imgInfo.pixelFormat); + if (bytesPerPixel == 0 || rowDataSize <=0 || + rowDataSize != ImageUtils::GetRowDataSizeByPixelFormat(imgInfo.size.width, imgInfo.pixelFormat)) { + IMAGE_LOGE("[ImageUtils] RowDataSizeIsVaild: bytesPerPixel or rowDataSize:%{public}d", rowDataSize); + return false; + } + return true; +} + +bool ImageUtils::CheckBufferSizeIsVaild(int32_t &bufferSize, uint64_t &expectedBufferSize, AllocatorType &allocatorType) +{ + if (bufferSize <= 0 || + expectedBufferSize > (allocatorType == AllocatorType::HEAP_ALLOC ? PIXEL_MAP_MAX_RAM_SIZE : INT_MAX) || + expectedBufferSize != static_cast(bufferSize)) { + IMAGE_LOGE("[ImageUtils] BufferSizeIsVaild: bufferSize invalid, expect:%{public}llu, actual:%{public}d", + static_cast(expectedBufferSize), bufferSize); + return false; + } + return true; +} + +bool ImageUtils::GetAlignedNumber(int32_t& number, int32_t align) +{ + if (number < 0 || align <= 0) { + return false; + } + int64_t res = number; + res = (res + align - 1) / align * align; + if (res > INT32_MAX) { + return false; + } + number = static_cast(res); + return true; +} + +uint16_t ImageUtils::GetRGBA1010102ColorR(uint32_t color) +{ + return (color >> RGBA1010102_R_SHIFT) & RGBA1010102_RGB_MASK; +} + +uint16_t ImageUtils::GetRGBA1010102ColorG(uint32_t color) +{ + return (color >> RGBA1010102_G_SHIFT) & RGBA1010102_RGB_MASK; +} + +uint16_t ImageUtils::GetRGBA1010102ColorB(uint32_t color) +{ + return (color >> RGBA1010102_B_SHIFT) & RGBA1010102_RGB_MASK; +} + +uint16_t ImageUtils::GetRGBA1010102ColorA(uint32_t color) +{ + return (color >> RGBA1010102_A_SHIFT) & RGBA1010102_ALPHA_MASK; +} } // namespace Media } // namespace OHOS -- Gitee