From 6d011d0e27d79b9c9fc7570770f5af958706e63a Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 16 Mar 2021 10:09:35 +0100 Subject: Fix: Cryptomatte load corrupt manifests. Seems like one of the example files on the cryptomatte github is malformed and blender crashes when loading that file. This change will try to load as much as possible from the manifest so it can still be used. This has also been reported to cryptomatte project. --- source/blender/blenkernel/intern/cryptomatte.cc | 5 ++++- source/blender/blenkernel/intern/cryptomatte_test.cc | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/source/blender/blenkernel/intern/cryptomatte.cc b/source/blender/blenkernel/intern/cryptomatte.cc index 74576b8bbbb..bc89fa85cea 100644 --- a/source/blender/blenkernel/intern/cryptomatte.cc +++ b/source/blender/blenkernel/intern/cryptomatte.cc @@ -410,6 +410,9 @@ static bool from_manifest(CryptomatteLayer &layer, blender::StringRefNull manife ref = ref.drop_prefix(quoted_name_len); ref = skip_whitespaces_(ref); + if (ref.is_empty()) { + return false; + } char colon = ref.front(); if (colon != ':') { return false; @@ -417,7 +420,7 @@ static bool from_manifest(CryptomatteLayer &layer, blender::StringRefNull manife ref = ref.drop_prefix(1); ref = skip_whitespaces_(ref); - if (ref.front() != '\"') { + if (ref.is_empty() || ref.front() != '\"') { return false; } diff --git a/source/blender/blenkernel/intern/cryptomatte_test.cc b/source/blender/blenkernel/intern/cryptomatte_test.cc index 7a86002cf6a..85ab7e43d22 100644 --- a/source/blender/blenkernel/intern/cryptomatte_test.cc +++ b/source/blender/blenkernel/intern/cryptomatte_test.cc @@ -173,4 +173,14 @@ TEST(cryptomatte, session_from_stamp_data) RE_FreeRenderResult(render_result2); } +/** + * Test method that contains known malformed manifests and makes sure that these can be parsed as + * best as possible. */ +TEST(cryptomatte, parsing_malformed_manifests) +{ + /* Manifest from multilayer.exr in the cryptomatte git-repository. */ + test_cryptomatte_manifest( + R"({"/obj/instance1:instances:0":"0d54c6cc","/obj/instance1:instances:1":"293d9340","/obj/instance1:instances:110":"ccb9e1f2","/obj/instance1:instances:111":"f8dd3a48","/obj/instance1:instances:112":"a99e07a8","/obj/instance1:instances:113":"e75599a4","/obj/instance1:instances:114":"794200f3","/obj/instance1:instances:115":"2a3a1728","/obj/instance1:instances:116":"478544a1","/obj/instance1:instances:117":"b2bd969a","/obj/instance1:instances:10":"3a0c8681","/obj/instance1:instances:11":"01e5970d","/obj/box:polygons:1":"9d416418","/obj/instance1:instances:100":"2dcd2966","/obj/instance1:instances:101":"9331cd82","/obj/instance1:instances:102":"df50fccb","/obj/instance1:instances:103":"97f8590d","/obj/instance1:instances:104":"bbcd220d","/obj/instance1:instances:105":"4ae06139","/obj/instance1:instances:106":"8873d5ea","/obj/instance1:instances:107":"39d8af8d","/obj/instance1:instances:108":"bb11bd4e","/obj/instance1:instances:109":"a32bba35"})", + R"({"\/obj\/box:polygons:1":"9d416418","\/obj\/instance1:instances:0":"0d54c6cc","\/obj\/instance1:instances:1":"293d9340","\/obj\/instance1:instances:10":"3a0c8681","\/obj\/instance1:instances:100":"2dcd2966","\/obj\/instance1:instances:101":"9331cd82","\/obj\/instance1:instances:102":"df50fccb","\/obj\/instance1:instances:103":"97f8590d","\/obj\/instance1:instances:104":"bbcd220d","\/obj\/instance1:instances:105":"4ae06139","\/obj\/instance1:instances:106":"8873d5ea","\/obj\/instance1:instances:107":"39d8af8d","\/obj\/instance1:instances:108":"bb11bd4e","\/obj\/instance1:instances:109":"a32bba35","\/obj\/instance1:instances:11":"01e5970d","\/obj\/instance1:instances:110":"ccb9e1f2","\/obj\/instance1:instances:111":"f8dd3a48","\/obj\/instance1:instances:112":"a99e07a8","\/obj\/instance1:instances:113":"e75599a4","\/obj\/instance1:instances:114":"794200f3","\/obj\/instance1:instances:115":"2a3a1728","\/obj\/instance1:instances:116":"478544a1","\/obj\/instance1:instances:117":"b2bd969a","\/obj\/instance1:instance)"); +} } // namespace blender::bke::cryptomatte::tests -- cgit v1.2.3