Fix a gif crash 74/282574/1
authorHeeyong Song <heeyong.song@samsung.com>
Thu, 6 Oct 2022 06:10:59 +0000 (15:10 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Thu, 6 Oct 2022 06:10:59 +0000 (15:10 +0900)
A crash ocurred when we load a gif file which exists but is not a gif

Change-Id: I5f3b2484b0cf8cd825e48922d2d3ba5a2af8b025

automated-tests/resources/invalid.gif [new file with mode: 0644]
automated-tests/src/dali-adaptor/utc-Dali-GifLoading.cpp
dali/internal/imaging/common/gif-loading.cpp

diff --git a/automated-tests/resources/invalid.gif b/automated-tests/resources/invalid.gif
new file mode 100644 (file)
index 0000000..8ec84ae
Binary files /dev/null and b/automated-tests/resources/invalid.gif differ
index b71cedd..03267a7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,6 +30,9 @@ static const char* gGif_100_None = TEST_RESOURCE_DIR "/canvas-none.gif";
 // this image if not exist, for negative test
 static const char* gGifNonExist = "non-exist.gif";
 
+// this image exists but it is not a gif file.
+static const char* gGifInvalid = TEST_RESOURCE_DIR "/invalid.gif";
+
 } // namespace
 
 void utc_dali_animated_image_loader_startup(void)
@@ -65,3 +68,14 @@ int UtcDaliAnimatedImageLoadingGetImageSizeN(void)
 
   END_TEST;
 }
+
+int UtcDaliAnimatedImageLoadingInvalidGif(void)
+{
+  Dali::AnimatedImageLoading animatedImageLoading = Dali::AnimatedImageLoading::New(gGifInvalid, true);
+  Dali::Devel::PixelBuffer   pixelBuffer          = animatedImageLoading.LoadFrame(0);
+
+  // The pixel buffer should be empty.
+  DALI_TEST_CHECK(!pixelBuffer);
+
+  END_TEST;
+}
index 4ca7dd4..88b8e1e 100644 (file)
@@ -1078,6 +1078,11 @@ bool ReadHeader(LoaderInfo&      loaderInfo,
         }
       }
     }
+    else
+    {
+      success = false;
+      DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
+    }
   }
   return success;
 }
@@ -1396,7 +1401,7 @@ public:
     mLoadSucceeded(false),
     mMutex()
   {
-    loaderInfo.gifAccessor = nullptr;
+    loaderInfo.gifAccessor              = nullptr;
     loaderInfo.fileData.fileName        = mUrl.c_str();
     loaderInfo.fileData.isLocalResource = isLocalResource;
   }
@@ -1411,6 +1416,10 @@ public:
     }
 
     mLoadSucceeded = ReadHeader(loaderInfo, imageProperties);
+    if(!mLoadSucceeded)
+    {
+      DALI_LOG_ERROR("ReadHeader is failed [%s]\n", mUrl.c_str());
+    }
     return mLoadSucceeded;
   }