(GifLoading) Fix SVACE Errors 91/166191/3
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 8 Jan 2018 16:57:21 +0000 (16:57 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 10 Jan 2018 17:01:40 +0000 (17:01 +0000)
Change-Id: I19db807bfc9c7f5d1fadabc336043b9d4c05ff23

adaptors/devel-api/adaptor-framework/gif-loading.cpp
adaptors/devel-api/adaptor-framework/gif-loading.h

index 06d7280..d6504e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -136,7 +136,7 @@ struct LoaderInfo
 
     const char *fileName;  /**< The absolute path of the file. */
     unsigned char *globalMap ;      /**< A pointer to the entire contents of the file that have been mapped with mmap(2). */
-    unsigned long long length;  /**< The length of the file in bytes. */
+    long long length;  /**< The length of the file in bytes. */
     int fileDescriptor; /**< The file descriptor. */
   };
 
@@ -639,7 +639,17 @@ bool ReadHeader( LoaderInfo &loaderInfo,
   }
 
   fileData.length = lseek( fileData.fileDescriptor, 0, SEEK_END );
-  lseek( fileData.fileDescriptor, 0, SEEK_SET );
+  if( fileData.length <= -1 )
+  {
+    close( fileData.fileDescriptor );
+    return false;
+  }
+
+  if( lseek( fileData.fileDescriptor, 0, SEEK_SET ) == -1 )
+  {
+    close( fileData.fileDescriptor );
+    return false;
+  }
 
   // map the file and store/track info
   fileData.globalMap  = reinterpret_cast<unsigned char *>( mmap(NULL, fileData.length, PROT_READ, MAP_SHARED, fileData.fileDescriptor, 0 ));
@@ -995,7 +1005,6 @@ open_file:
           {
             FillFrame( thisFrame->data, prop.w, gif, frameInfo, x, y, w, h );
           }
-
           else if( frameInfo->dispose == DISPOSE_PREVIOUS ) // GIF_DISPOSE_RESTORE
           {
             int prevIndex = 2;
@@ -1003,8 +1012,12 @@ open_file:
             {
               // Find last preserved frame.
               lastPreservedFrame = FindFrame( animated, imageNumber - prevIndex );
+              if( ! lastPreservedFrame )
+              {
+                LOADERR( "LOAD_ERROR_LAST_PRESERVED_FRAME_NOT_FOUND" );
+              }
               prevIndex++;
-            } while( lastPreservedFrame->info.dispose == DISPOSE_PREVIOUS );
+            } while( lastPreservedFrame && lastPreservedFrame->info.dispose == DISPOSE_PREVIOUS );
 
             if ( lastPreservedFrame )
             {
index fb1da2f..dd0a94e 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_INTERNAL_GIF_LOADING_H__
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
@@ -51,6 +51,13 @@ public:
    */
   GifLoading( const std::string& url );
 
+  // Moveable but not copyable
+
+  GifLoading( const GifLoading& ) = delete;
+  GifLoading& operator=( const GifLoading& ) = delete;
+  GifLoading( GifLoading&& ) = default;
+  GifLoading& operator=( GifLoading&& ) = default;
+
   /**
    * @brief Destructor
    */