Cleanup/Fix: Move 'security' check on constraints 'data' into 'read_data' code.

Having this check is likely no more meaningful (it seems to have been
added ages ago), but keeping it around does not hurt either. And it
could avoid crashes in some file corruption cases e.g.

However, having it in 'lib_link' code of constraints is useless for
sure, since that data pointer may have already been accessed in the
'read_data' one. And of course, logically it belongs to 'read_data'
anyway, since it's related (and only affects) private local data, not
pointers to other IDs...

No behavioral change expected here.
This commit is contained in:
Bastien Montagne 2023-08-14 17:23:34 +02:00
parent 5c2c95f80d
commit 7ddea7e90a
1 changed files with 8 additions and 5 deletions

View File

@ -6491,6 +6491,14 @@ void BKE_constraint_blend_read_data(BlendDataReader *reader, ID *id_owner, ListB
BLO_read_list(reader, lb);
LISTBASE_FOREACH (bConstraint *, con, lb) {
BLO_read_data_address(reader, &con->data);
/* Patch for error introduced by changing constraints (don't know how). */
/* NOTE(@ton): If `con->data` type changes, DNA cannot resolve the pointer!. */
/* FIXME This is likely dead code actually, since it used to be in
* #BKE_constraint_blend_read_lib, so it would have crashed on null pointer access in any of
* the code below? But does not hurt to keep it around as a safety measure. */
if (con->data == nullptr) {
con->type = CONSTRAINT_TYPE_NULL;
}
/* If linking from a library, clear 'local' library override flag. */
if (ID_IS_LINKED(id_owner)) {
@ -6567,11 +6575,6 @@ void BKE_constraint_blend_read_lib(BlendLibReader *reader, ID *id, ListBase *con
/* legacy fixes */
LISTBASE_FOREACH (bConstraint *, con, conlist) {
/* Patch for error introduced by changing constraints (don't know how). */
/* NOTE(@ton): If `con->data` type changes, DNA cannot resolve the pointer!. */
if (con->data == nullptr) {
con->type = CONSTRAINT_TYPE_NULL;
}
/* own ipo, all constraints have it */
BLO_read_id_address(reader, id, &con->ipo); /* XXX deprecated - old animation system */
}