diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-09-30 17:44:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-09-30 17:44:16 +0400 |
commit | 4b8fee11b676b9995cdf9f54e037478f57f9d912 (patch) | |
tree | 64a284b04b391ddbe59ac089e117de41a7e86511 /source/blender/blenloader/intern/readfile.c | |
parent | ae25238f41a949696cd95d1aeecd778ddb7cdce1 (diff) |
workaround for [#36314], ensure all id-properties are groups on load (which are expected to be groups).
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 193177bb33d..fad0b709baf 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1776,6 +1776,27 @@ static void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData } } +#define IDP_DirectLinkGroup_OrFree(prop, switch_endian, fd) \ + _IDP_DirectLinkGroup_OrFree(prop, switch_endian, fd, __func__) + +static void _IDP_DirectLinkGroup_OrFree(IDProperty **prop, int switch_endian, FileData *fd, + const char *caller_func_id) +{ + if (*prop) { + if ((*prop)->type == IDP_GROUP) { + IDP_DirectLinkGroup(*prop, switch_endian, fd); + } + else { + /* corrupt file! */ + printf("%s: found non group data, freeing type %d!\n", + caller_func_id, (*prop)->type); + /* don't risk id, data's likely corrupt. */ + // IDP_FreeProperty(*prop); + *prop = NULL; + } + } +} + /* stub function */ static void IDP_LibLinkProperty(IDProperty *UNUSED(prop), int UNUSED(switch_endian), FileData *UNUSED(fd)) { @@ -1788,9 +1809,8 @@ static void direct_link_id(FileData *fd, ID *id) /*link direct data of ID properties*/ if (id->properties) { id->properties = newdataadr(fd, id->properties); - if (id->properties) { /* this case means the data was written incorrectly, it should not happen */ - IDP_DirectLinkProperty(id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - } + /* this case means the data was written incorrectly, it should not happen */ + IDP_DirectLinkGroup_OrFree(&id->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } } @@ -2041,7 +2061,7 @@ static void direct_link_fmodifiers(FileData *fd, ListBase *list) FMod_Python *data = (FMod_Python *)fcm->data; data->prop = newdataadr(fd, data->prop); - IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + IDP_DirectLinkGroup_OrFree(&data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } break; } @@ -2596,8 +2616,7 @@ static void lib_verify_nodetree(Main *main, int UNUSED(open)) static void direct_link_node_socket(FileData *fd, bNodeSocket *sock) { sock->prop = newdataadr(fd, sock->prop); - if (sock->prop) - IDP_DirectLinkProperty(sock->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + IDP_DirectLinkGroup_OrFree(&sock->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); sock->link = newdataadr(fd, sock->link); sock->typeinfo = NULL; @@ -2635,8 +2654,7 @@ static void direct_link_nodetree(FileData *fd, bNodeTree *ntree) link_list(fd, &node->outputs); node->prop = newdataadr(fd, node->prop); - if (node->prop) - IDP_DirectLinkProperty(node->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + IDP_DirectLinkGroup_OrFree(&node->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); link_list(fd, &node->internal_links); for (link = node->internal_links.first; link; link = link->next) { @@ -2794,8 +2812,7 @@ static void direct_link_constraints(FileData *fd, ListBase *lb) link_list(fd, &data->targets); data->prop = newdataadr(fd, data->prop); - if (data->prop) - IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + IDP_DirectLinkGroup_OrFree(&data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); break; } case CONSTRAINT_TYPE_SPLINEIK: @@ -2894,8 +2911,7 @@ static void direct_link_bones(FileData *fd, Bone *bone) bone->parent = newdataadr(fd, bone->parent); bone->prop = newdataadr(fd, bone->prop); - if (bone->prop) - IDP_DirectLinkProperty(bone->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + IDP_DirectLinkGroup_OrFree(&bone->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); bone->flag &= ~BONE_DRAW_ACTIVE; @@ -4534,8 +4550,7 @@ static void direct_link_pose(FileData *fd, bPose *pose) direct_link_constraints(fd, &pchan->constraints); pchan->prop = newdataadr(fd, pchan->prop); - if (pchan->prop) - IDP_DirectLinkProperty(pchan->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + IDP_DirectLinkGroup_OrFree(&pchan->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); pchan->mpath = newdataadr(fd, pchan->mpath); if (pchan->mpath) @@ -5432,10 +5447,7 @@ static void direct_link_scene(FileData *fd, Scene *sce) } if (sce->r.ffcodecdata.properties) { sce->r.ffcodecdata.properties = newdataadr(fd, sce->r.ffcodecdata.properties); - if (sce->r.ffcodecdata.properties) { - IDP_DirectLinkProperty(sce->r.ffcodecdata.properties, - (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - } + IDP_DirectLinkGroup_OrFree(&sce->r.ffcodecdata.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } link_list(fd, &(sce->markers)); @@ -6129,8 +6141,7 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) ui_list->type = NULL; ui_list->dyn_data = NULL; ui_list->properties = newdataadr(fd, ui_list->properties); - if (ui_list->properties) - IDP_DirectLinkProperty(ui_list->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + IDP_DirectLinkGroup_OrFree(&ui_list->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } if (spacetype == SPACE_EMPTY) { @@ -9756,8 +9767,7 @@ static void lib_link_all(FileData *fd, Main *main) static void direct_link_keymapitem(FileData *fd, wmKeyMapItem *kmi) { kmi->properties = newdataadr(fd, kmi->properties); - if (kmi->properties) - IDP_DirectLinkProperty(kmi->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); + IDP_DirectLinkGroup_OrFree(&kmi->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); kmi->ptr = NULL; kmi->flag &= ~KMI_UPDATE; } @@ -9814,9 +9824,7 @@ static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead) for (addon = user->addons.first; addon; addon = addon->next) { addon->prop = newdataadr(fd, addon->prop); - if (addon->prop) { - IDP_DirectLinkProperty(addon->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - } + IDP_DirectLinkGroup_OrFree(&addon->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } // XXX |