edje - fix crash on loading ancient edje files

ancient edje files dont put hash strings in the file dictionary but
instead inline and thus the strings cannot be direct added... silly
ancient files.

this is a horrible ugly workaround this but there isn't really
anything better than trying to detect such files (which dont seem to
have an older version in them i can find?) so detect by pointer
address and mapping the file.

this fixes T5138

@fix
This commit is contained in:
Carsten Haitzler 2017-02-03 14:39:57 +09:00
parent e94967da72
commit 9c3df02c41
2 changed files with 32 additions and 1 deletions

View File

@ -278,6 +278,12 @@ _edje_file_coll_open(Edje_File *edf, const char *coll)
return edc;
}
// XXX: this is not pretty. some oooooold edje files do not store strings
// in their dictionary for hashes. this works around crashes loading such
// files
extern size_t _edje_data_string_mapping_size;
extern void *_edje_data_string_mapping;
static Edje_File *
_edje_file_open(const Eina_File *f, int *error_ret, time_t mtime, Eina_Bool coll)
{
@ -289,6 +295,8 @@ _edje_file_open(const Eina_File *f, int *error_ret, time_t mtime, Eina_Bool coll
Eina_List *l, *ll;
Eet_File *ef;
char *name;
void *mapping;
size_t mapping_size;
ef = eet_mmap(f);
if (!ef)
@ -296,7 +304,21 @@ _edje_file_open(const Eina_File *f, int *error_ret, time_t mtime, Eina_Bool coll
*error_ret = EDJE_LOAD_ERROR_UNKNOWN_FORMAT;
return NULL;
}
// XXX: ancient edje file workaround
mapping = eina_file_map_all((Eina_File *)f, EINA_FILE_SEQUENTIAL);
if (mapping)
{
mapping_size = eina_file_size_get(f);
_edje_data_string_mapping = mapping;
_edje_data_string_mapping_size = mapping_size;
}
edf = eet_data_read(ef, _edje_edd_edje_file, "edje/file");
// XXX: ancient edje file workaround
if (mapping)
{
eina_file_map_free((Eina_File *)f, mapping);
_edje_data_string_mapping = NULL;
}
if (!edf)
{
*error_ret = EDJE_LOAD_ERROR_CORRUPT_FILE;

View File

@ -639,6 +639,9 @@ _edje_description_variant_type_set(const char *type, void *data, Eina_Bool unkno
return EINA_FALSE;
}
size_t _edje_data_string_mapping_size = 0;
void *_edje_data_string_mapping = NULL;
static Eina_Hash *
_edje_eina_hash_add_alloc(Eina_Hash *hash,
const char *key,
@ -650,7 +653,13 @@ _edje_eina_hash_add_alloc(Eina_Hash *hash,
if (!hash)
return NULL;
eina_hash_direct_add(hash, key, data);
// XXX: ancient edje file workaround
if ((_edje_data_string_mapping) &&
((key >= (char *)_edje_data_string_mapping) &&
(key < ((char *)_edje_data_string_mapping + _edje_data_string_mapping_size))))
eina_hash_direct_add(hash, key, data);
else
eina_hash_add(hash, key, data);
return hash;
}