Package Upload
[framework/uifw/eet.git] / src / lib / eet_data.c
index d502f44..bd6bbd9 100644 (file)
@@ -1946,6 +1946,37 @@ eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
    Eet_Data_Element *ede;
    Eet_Data_Element *tmp;
 
+   /* Sanity check to avoid crash later at runtime */
+   if (type < EET_T_UNKNOW ||
+       type >= EET_T_LAST)
+     {
+        CRIT("Preventing later bug due to unknow type: %i", type);
+        return ;
+     }
+   if (offset < 0)
+     {
+        CRIT("Preventing later buffer underrun : offset = %i", offset);
+        return ;
+     }
+   if (offset > edd->size)
+     {
+        CRIT("Preventing later buffer overrun : offset = %i in a structure of %i bytes", offset, edd->size);
+        return ;
+     }
+   if (group_type == EET_G_UNKNOWN && type != EET_T_UNKNOW)
+     {
+        if (offset + eet_basic_codec[type - 1].size > edd->size)
+          {
+             CRIT("Preventing later buffer overrun : offset = %i, size = %i in a structure of %i bytes", offset, eet_basic_codec[type - 1].size, edd->size);
+             return ;
+          }
+     }
+   else if ((offset + sizeof (void*)) > (unsigned int) edd->size)
+     {
+        CRIT("Preventing later buffer overrun : offset = %i, estimated size = %i in a structure of %i bytes", offset, sizeof (void*), edd->size);
+        return ;
+     }
+
    /* UNION, VARIANT type would not work with simple type, we need a way to map the type. */
    if ((group_type == EET_G_UNION
         || group_type == EET_G_VARIANT)
@@ -2114,7 +2145,7 @@ eet_data_write_cipher(Eet_File            *ef,
                       const char          *name,
                       const char          *cipher_key,
                       const void          *data,
-                      int                  compress)
+                      int                  comp)
 {
    Eet_Dictionary *ed;
    void *data_enc;
@@ -2127,7 +2158,7 @@ eet_data_write_cipher(Eet_File            *ef,
    if (!data_enc)
      return 0;
 
-   val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
+   val = eet_write_cipher(ef, name, data_enc, size, comp, cipher_key);
    free(data_enc);
    return val;
 }
@@ -2137,9 +2168,9 @@ eet_data_write(Eet_File            *ef,
                Eet_Data_Descriptor *edd,
                const char          *name,
                const void          *data,
-               int                  compress)
+               int                  comp)
 {
-   return eet_data_write_cipher(ef, edd, name, NULL, data, compress);
+   return eet_data_write_cipher(ef, edd, name, NULL, data, comp);
 }
 
 static void
@@ -3667,7 +3698,7 @@ eet_data_get_array(Eet_Free_Context     *context,
    if (ede)
      {
         if (IS_POINTER_TYPE(type))
-          subsize = eet_basic_codec[ede->type].size;
+          subsize = eet_basic_codec[ede->type - 1].size;
         else
           subsize = ede->subtype->size;
 
@@ -4386,7 +4417,7 @@ eet_data_put_array(Eet_Dictionary      *ed,
      eet_data_encode(ed, ds, data, ede->name, size, ede->type, ede->group_type);
 
    if (IS_POINTER_TYPE(ede->type))
-     subsize = eet_basic_codec[ede->type].size;
+     subsize = eet_basic_codec[ede->type - 1].size;
    else
      subsize = ede->subtype->size;
 
@@ -4670,7 +4701,7 @@ eet_data_undump_cipher(Eet_File   *ef,
                        const char *cipher_key,
                        const char *text,
                        int         textlen,
-                       int         compress)
+                       int         comp)
 {
    Eet_Dictionary *ed;
    void *data_enc;
@@ -4683,7 +4714,7 @@ eet_data_undump_cipher(Eet_File   *ef,
    if (!data_enc)
      return 0;
 
-   val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
+   val = eet_write_cipher(ef, name, data_enc, size, comp, cipher_key);
    free(data_enc);
    return val;
 }
@@ -4693,9 +4724,9 @@ eet_data_undump(Eet_File   *ef,
                 const char *name,
                 const char *text,
                 int         textlen,
-                int         compress)
+                int         comp)
 {
-   return eet_data_undump_cipher(ef, name, NULL, text, textlen, compress);
+   return eet_data_undump_cipher(ef, name, NULL, text, textlen, comp);
 }
 
 EAPI void *
@@ -4844,7 +4875,7 @@ eet_data_node_write_cipher(Eet_File   *ef,
                            const char *name,
                            const char *cipher_key,
                            Eet_Node   *node,
-                           int         compress)
+                           int         comp)
 {
    Eet_Dictionary *ed;
    void *data_enc;
@@ -4857,7 +4888,7 @@ eet_data_node_write_cipher(Eet_File   *ef,
    if (!data_enc)
      return 0;
 
-   val = eet_write_cipher(ef, name, data_enc, size, compress, cipher_key);
+   val = eet_write_cipher(ef, name, data_enc, size, comp, cipher_key);
    free(data_enc);
    return val;
 }