Fix readfile linking code not protected against invalid BHeads.

Follow up to 6ba58a8303, apply similar checks to code loading
linked data from blendfile libraries.
This commit is contained in:
Bastien Montagne
2024-11-05 14:38:30 +01:00
parent 828f60b742
commit e2b1e9912c

View File

@@ -3986,6 +3986,13 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
if (bhead == nullptr) {
return;
}
/* In 2.50+ file identifier for screens is patched, forward compatibility. */
if (bhead->code == ID_SCRN) {
bhead->code = ID_SCR;
}
if (!blo_bhead_is_id_valid_type(bhead)) {
return;
}
if (bhead->code == ID_LINK_PLACEHOLDER) {
/* Placeholder link to data-block in another library. */
@@ -4056,11 +4063,6 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
}
else {
/* Data-block in same library. */
/* In 2.50+ file identifier for screens is patched, forward compatibility. */
if (bhead->code == ID_SCRN) {
bhead->code = ID_SCR;
}
ID *id = library_id_is_yet_read(fd, mainvar, bhead);
if (id == nullptr) {
read_libblock(
@@ -4166,7 +4168,7 @@ static ID *link_named_part(
BLI_assert(BKE_idtype_idcode_is_linkable(idcode) && BKE_idtype_idcode_is_valid(idcode));
if (bhead) {
if (bhead && blo_bhead_is_id_valid_type(bhead)) {
id = library_id_is_yet_read(fd, mainl, bhead);
if (id == nullptr) {
/* not read yet */
@@ -4199,8 +4201,7 @@ static ID *link_named_part(
id = nullptr;
}
/* if we found the id but the id is nullptr, this is really bad */
BLI_assert(!((bhead != nullptr) && (id == nullptr)));
/* NOTE: `id` may be `nullptr` even if a BHead was found, in case e.g. it is an invalid BHead. */
return id;
}