This commit enables Blender 4.5 to use (to some extent) blendfiles from Blender 5.0 and later using 'long' ID names (i.e. ID names over 63 bytes). On a more general perspective, it also introduces safer handling of potentially corrupted ID names in a blendfile. This is achieved by carefully checking for non-null terminated ID names early on in readfile process, and then: * Truncating and ensuring uniqueness of ID names. * Doing similar process for action slot and slot users identifiers. * In linking (and appending) context, such IDs are totally ignored. They are not listed, and are considered as missing if some other (valid) linked ID attempt to indirectly link them). * Informing users through usual reporting ways. Technically, this mainly changes two areas of the readfile code related to IDs themselves: * The utils `blo_bhead_id_name` that returns the ID name of an ID BHead, without actually reading that ID, now check for a valid null-terminated string of `MAX_ID_NAME` max size, and returns a `nullptr` on error. _This essentially prevents listing and linking such IDs, in any way._ * The actual ID reading code (`read_id_struct`) does the same check, and truncate the ID name to its maximum allowed length. * Both of above checks also set a new FileData flag (`FD_FLAGS_HAS_LONG_ID_NAME`), which is used to ensure that ID names (and related actions slots identifiers) remain unique, and report to info to the user. Implements #137608. Branched out from !137196. Co-authored-by: michal.krupa <michal.krupa@cdprojektred.com> Co-authored-by: Campbell Barton <ideasman42@gmail.com> Pull Request: https://projects.blender.org/blender/blender/pulls/139336
52 lines
1.6 KiB
C++
52 lines
1.6 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup blenloader
|
|
*/
|
|
#include "BLO_readfile.hh"
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "BLI_string.h"
|
|
|
|
#include "BKE_main.hh"
|
|
|
|
#include "DNA_ID.h"
|
|
|
|
TempLibraryContext *BLO_library_temp_load_id(Main *real_main,
|
|
const char *blend_file_path,
|
|
const short idcode,
|
|
const char *idname,
|
|
ReportList *reports)
|
|
{
|
|
TempLibraryContext *temp_lib_ctx = MEM_callocN<TempLibraryContext>(__func__);
|
|
temp_lib_ctx->bmain_base = BKE_main_new();
|
|
temp_lib_ctx->bf_reports.reports = reports;
|
|
|
|
/* Copy the file path so any path remapping is performed properly. */
|
|
STRNCPY(temp_lib_ctx->bmain_base->filepath, real_main->filepath);
|
|
|
|
BlendHandle *blendhandle = BLO_blendhandle_from_file(blend_file_path, &temp_lib_ctx->bf_reports);
|
|
|
|
LibraryLink_Params lib_link_params;
|
|
BLO_library_link_params_init(&lib_link_params, temp_lib_ctx->bmain_base, 0, ID_TAG_TEMP_MAIN);
|
|
|
|
Main *bmain_lib = BLO_library_link_begin(&blendhandle, blend_file_path, &lib_link_params);
|
|
|
|
temp_lib_ctx->temp_id = BLO_library_link_named_part(
|
|
bmain_lib, &blendhandle, idcode, idname, &lib_link_params);
|
|
|
|
BLO_library_link_end(bmain_lib, &blendhandle, &lib_link_params, reports);
|
|
BLO_blendhandle_close(blendhandle);
|
|
|
|
return temp_lib_ctx;
|
|
}
|
|
|
|
void BLO_library_temp_free(TempLibraryContext *temp_lib_ctx)
|
|
{
|
|
BKE_main_free(temp_lib_ctx->bmain_base);
|
|
MEM_freeN(temp_lib_ctx);
|
|
}
|