Fix error when importing bad subtitle file (#2838).
authorCarl Hetherington <cth@carlh.net>
Thu, 27 Jun 2024 18:14:31 +0000 (20:14 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 27 Jun 2024 18:14:31 +0000 (20:14 +0200)
The subtitle XML refers to a font with no corresponding <LoadFont>.

src/lib/font_id_allocator.cc
test/data
test/subtitle_font_id_test.cc

index 112dd262bacfd98652c6ad0620808b4b17cf986f..5e4ae9c0f2d1d4bd8b3426d3009c5a550a735c71 100644 (file)
@@ -116,7 +116,9 @@ string
 FontIDAllocator::font_id(int reel_index, string asset_id, string font_id) const
 {
        auto iter = _map.find(Font(reel_index, asset_id, font_id));
-       DCPOMATIC_ASSERT(iter != _map.end());
+       if (iter == _map.end()) {
+               return default_font_id();
+       }
        return String::compose("%1_%2", iter->second, font_id);
 }
 
index 4cb08962ba07e99c442cb12091c0347d84d8fd89..6a4fa8b7c13e4f09fcee995191a2c86e1eff9d6d 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 4cb08962ba07e99c442cb12091c0347d84d8fd89
+Subproject commit 6a4fa8b7c13e4f09fcee995191a2c86e1eff9d6d
index bc09a9cf1e95ad1254890f67aa70649f6077e11d..12d804d20a23b0de9eb31f68bf485a317b349d7d 100644 (file)
@@ -302,3 +302,17 @@ BOOST_AUTO_TEST_CASE(no_error_with_ccap_that_mentions_no_font)
        while (!player.pass()) {}
 }
 
+
+BOOST_AUTO_TEST_CASE(cope_with_unloaded_font_id)
+{
+       /* This file has a <Font> with an ID that corresponds to no <LoadFont> */
+       auto subs = content_factory("test/data/unloaded_font.xml")[0];
+       auto film = new_test_film2("cope_with_unloaded_font_id", { subs });
+       make_and_verify_dcp(
+               film,
+               {
+                       dcp::VerificationNote::Code::MISSING_SUBTITLE_LANGUAGE,
+                       dcp::VerificationNote::Code::MISSING_CPL_METADATA,
+               });
+}
+