Prevent to decode png when the pixel buffer cannot be created 29/303529/3
authorseungho baek <sbsh.baek@samsung.com>
Tue, 2 Jan 2024 01:48:58 +0000 (10:48 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Tue, 2 Jan 2024 03:59:43 +0000 (12:59 +0900)
Change-Id: Ibf86d02ae4f55590d6f021ac9ebc27b0cfe516fc
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
dali/internal/imaging/common/loader-png.cpp

index a84b205..8351aa7 100644 (file)
@@ -300,6 +300,18 @@ bool LoadBitmapFromPng(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
         break;
     }
   }
+
+  // decode the whole image into bitmap buffer
+  auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat)).GetBuffer();
+
+  DALI_ASSERT_DEBUG(pixels);
+
+  if(!pixels)
+  {
+    DALI_LOG_ERROR("PixelBuffer couldn't be created\n");
+    return false;
+  }
+
   rows = reinterpret_cast<png_bytep*>(malloc(sizeof(png_bytep) * height));
   if(DALI_UNLIKELY(!rows))
   {
@@ -307,11 +319,6 @@ bool LoadBitmapFromPng(const Dali::ImageLoader::Input& input, Dali::Devel::Pixel
     return false;
   }
 
-  // decode the whole image into bitmap buffer
-  auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat)).GetBuffer();
-
-  DALI_ASSERT_DEBUG(pixels);
-
   for(y = 0; y < height; y++)
   {
     rows[y] = pixels + y * stride;