From 31c09e22b74e3a4cf5c16952f8634caea3920625 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 7 Apr 2023 20:59:44 +0200 Subject: Add test for too many subtitle namespaces. --- src/verify.cc | 20 ++++++++++++++++++++ src/verify.h | 4 ++++ 2 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/verify.cc b/src/verify.cc index 81ca0bc9..6a1cbd2d 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -58,6 +58,7 @@ #include "stereo_picture_frame.h" #include "verify.h" #include "verify_j2k.h" +#include #include #include #include @@ -786,15 +787,32 @@ verify_subtitle_asset ( notes.push_back ({VerificationNote::Type::WARNING, VerificationNote::Code::MISSED_CHECK_OF_ENCRYPTED}); } + auto namespace_count = [](shared_ptr asset, string root_node) { + cxml::Document doc(root_node); + doc.read_string(asset->raw_xml().get()); + auto root = dynamic_cast(doc.node())->cobj(); + int count = 0; + for (auto ns = root->nsDef; ns != nullptr; ns = ns->next) { + ++count; + } + return count; + }; + auto interop = dynamic_pointer_cast(asset); if (interop) { verify_interop_subtitle_asset(interop, notes); + if (namespace_count(asset, "DCSubtitle") > 1) { + notes.push_back({ VerificationNote::Type::WARNING, VerificationNote::Code::INCORRECT_SUBTITLE_NAMESPACE_COUNT, asset->id() }); + } } auto smpte = dynamic_pointer_cast(asset); if (smpte) { verify_smpte_timed_text_asset (smpte, reel_asset_duration, notes); verify_smpte_subtitle_asset (smpte, notes, state); + if (namespace_count(asset, "SubtitleReel") > 1) { + notes.push_back({ VerificationNote::Type::WARNING, VerificationNote::Code::INCORRECT_SUBTITLE_NAMESPACE_COUNT, asset->id()}); + } } } @@ -2019,6 +2037,8 @@ dcp::note_to_string (VerificationNote note) "Frame %1 has an image component that is too large (component %2 is %3 bytes in size).", note.frame().get(), note.component().get(), note.size().get() ); + case VerificationNote::Code::INCORRECT_SUBTITLE_NAMESPACE_COUNT: + return String::compose("The XML in the subtitle asset %1 has more than one namespace declaration.", note.note().get()); } return ""; diff --git a/src/verify.h b/src/verify.h index 69a10292..48c06577 100644 --- a/src/verify.h +++ b/src/verify.h @@ -444,6 +444,10 @@ public: * size contains the invalid size in bytes. */ INVALID_JPEG2000_TILE_PART_SIZE, + /** A subtitle XML root node has more than one namespace (xmlns) declaration. + * note contains the asset ID + */ + INCORRECT_SUBTITLE_NAMESPACE_COUNT }; VerificationNote (Type type, Code code) -- cgit v1.2.3