From 4bb6513b7db9c76f8ff740f34bc1c4f1bd360a29 Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Sat, 27 Sep 2025 01:23:05 +0200 Subject: [PATCH] Fix #146822: Ensure safe names are used for custom Alembic attributes We did not sanitize the names used for UV maps or Color attributes when exporting to Alembic. Names containing characters like ':' or '/' would cause an unhandled exception from Alembic. Pull Request: https://projects.blender.org/blender/blender/pulls/146867 --- .../io/alembic/exporter/abc_hierarchy_iterator.cc | 8 ++------ source/blender/io/alembic/intern/abc_customdata.cc | 13 ++++++------- source/blender/io/alembic/intern/abc_util.cc | 11 ++++++----- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc index c83daac096f..a9eb8f94731 100644 --- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc +++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc @@ -13,6 +13,7 @@ #include "abc_writer_nurbs.h" #include "abc_writer_points.h" #include "abc_writer_transform.h" +#include "intern/abc_util.h" #include #include @@ -83,12 +84,7 @@ void ABCHierarchyIterator::release_writer(AbstractHierarchyWriter *writer) std::string ABCHierarchyIterator::make_valid_name(const std::string &name) const { - std::string abc_name(name); - std::replace(abc_name.begin(), abc_name.end(), ' ', '_'); - std::replace(abc_name.begin(), abc_name.end(), '.', '_'); - std::replace(abc_name.begin(), abc_name.end(), ':', '_'); - std::replace(abc_name.begin(), abc_name.end(), '/', '_'); - return abc_name; + return get_valid_abc_name(name.c_str()); } ObjectIdentifier ABCHierarchyIterator::determine_graph_index_object( diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc index 963f3f5aa44..3603d7c3578 100644 --- a/source/blender/io/alembic/intern/abc_customdata.cc +++ b/source/blender/io/alembic/intern/abc_customdata.cc @@ -8,6 +8,7 @@ #include "abc_customdata.h" #include "abc_axis_conversion.h" +#include "abc_util.h" #include #include @@ -148,7 +149,7 @@ const char *get_uv_sample(UVSample &sample, const CDStreamConfig &config, Custom static void write_uv(const OCompoundProperty &prop, CDStreamConfig &config, const void *data, - const char *name) + const std::string &uv_map_name) { std::vector indices; std::vector uvs; @@ -159,11 +160,10 @@ static void write_uv(const OCompoundProperty &prop, return; } - std::string uv_map_name(name); OV2fGeomParam param = config.abc_uv_maps[uv_map_name]; if (!param.valid()) { - param = OV2fGeomParam(prop, name, true, kFacevaryingScope, 1); + param = OV2fGeomParam(prop, uv_map_name, true, kFacevaryingScope, 1); } OV2fGeomParam::Sample sample(V2fArraySample(&uvs.front(), uvs.size()), UInt32ArraySample(&indices.front(), indices.size()), @@ -213,7 +213,7 @@ static void get_cols(const CDStreamConfig &config, static void write_mcol(const OCompoundProperty &prop, CDStreamConfig &config, const void *data, - const char *name) + const std::string &vcol_name) { std::vector indices; std::vector buffer; @@ -224,11 +224,10 @@ static void write_mcol(const OCompoundProperty &prop, return; } - std::string vcol_name(name); OC4fGeomParam param = config.abc_vertex_colors[vcol_name]; if (!param.valid()) { - param = OC4fGeomParam(prop, name, true, kFacevaryingScope, 1); + param = OC4fGeomParam(prop, vcol_name, true, kFacevaryingScope, 1); } OC4fGeomParam::Sample sample(C4fArraySample(&buffer.front(), buffer.size()), @@ -289,7 +288,7 @@ void write_custom_data(const OCompoundProperty &prop, for (int i = 0; i < tot_layers; i++) { const void *cd_data = CustomData_get_layer_n(data, cd_data_type, i); - const char *name = CustomData_get_layer_name(data, cd_data_type, i); + std::string name = get_valid_abc_name(CustomData_get_layer_name(data, cd_data_type, i)); if (cd_data_type == CD_PROP_FLOAT2) { /* Already exported. */ diff --git a/source/blender/io/alembic/intern/abc_util.cc b/source/blender/io/alembic/intern/abc_util.cc index bfd32500aa9..72554a08116 100644 --- a/source/blender/io/alembic/intern/abc_util.cc +++ b/source/blender/io/alembic/intern/abc_util.cc @@ -28,11 +28,12 @@ namespace blender::io::alembic { std::string get_valid_abc_name(const char *name) { - std::string name_string(name); - std::replace(name_string.begin(), name_string.end(), ' ', '_'); - std::replace(name_string.begin(), name_string.end(), '.', '_'); - std::replace(name_string.begin(), name_string.end(), ':', '_'); - return name_string; + std::string abc_name(name); + std::replace(abc_name.begin(), abc_name.end(), ' ', '_'); + std::replace(abc_name.begin(), abc_name.end(), '.', '_'); + std::replace(abc_name.begin(), abc_name.end(), ':', '_'); + std::replace(abc_name.begin(), abc_name.end(), '/', '_'); + return abc_name; } Imath::M44d convert_matrix_datatype(const float mat[4][4])