Give better errors when invalid urn:uuid: strings are found (DoM #2521).
authorCarl Hetherington <cth@carlh.net>
Wed, 26 Apr 2023 14:42:43 +0000 (16:42 +0200)
committerCarl Hetherington <cth@carlh.net>
Wed, 26 Apr 2023 14:42:47 +0000 (16:42 +0200)
src/exceptions.cc
src/exceptions.h
src/util.cc
src/verify.cc

index 96a9a696674fe23a8c80922364b0adc0d9b9f7cb..e86a3b890824eacd69282d4ca44ef4ff97f14da4 100644 (file)
@@ -205,3 +205,10 @@ InconsistentValidityPeriodError::InconsistentValidityPeriodError()
 
 }
 
+
+BadURNUUIDError::BadURNUUIDError(string bad_id)
+       : runtime_error(String::compose("Badly-formed URN UUID %1", bad_id))
+{
+
+}
+
index 99e55b2878ab1cd784da76d47c963f31427ad0e7..8d85f02a02557b580ef0500800cc4550c8db8fd6 100644 (file)
@@ -323,6 +323,14 @@ public:
        InconsistentValidityPeriodError();
 };
 
+
+class BadURNUUIDError : public std::runtime_error
+{
+public:
+       BadURNUUIDError(std::string bad_id);
+};
+
+
 }
 
 
index 9cc35ad6094c68e4774c3ede8fc615f7ef6710d6..bbfcd30ebbfb9606d8f238b3545dcf89bbddd7a7 100644 (file)
@@ -314,7 +314,10 @@ dcp::find_child (xmlpp::Node const * node, string name)
 string
 dcp::remove_urn_uuid (string raw)
 {
-       DCP_ASSERT (raw.substr(0, 9) == "urn:uuid:");
+       if (raw.substr(0, 9) != "urn:uuid:") {
+               throw BadURNUUIDError(raw);
+       }
+
        return raw.substr (9);
 }
 
index b49695c7909567a89aaf8052c56e67fa71a4609c..c42a10d4b961522596b31c75a65e0b412c001502 100644 (file)
@@ -1780,6 +1780,8 @@ dcp::verify (
                        notes.push_back ({VerificationNote::Type::ERROR, VerificationNote::Code::FAILED_READ, string(e.what())});
                } catch (MXFFileError& e) {
                        notes.push_back ({VerificationNote::Type::ERROR, VerificationNote::Code::FAILED_READ, string(e.what())});
+               } catch (BadURNUUIDError& e) {
+                       notes.push_back({VerificationNote::Type::ERROR, VerificationNote::Code::FAILED_READ, string(e.what())});
                } catch (cxml::Error& e) {
                        notes.push_back ({VerificationNote::Type::ERROR, VerificationNote::Code::FAILED_READ, string(e.what())});
                }
@@ -1859,7 +1861,7 @@ dcp::note_to_string (VerificationNote note)
        case VerificationNote::Code::INVALID_XML:
                return String::compose("An XML file is badly formed: %1 (%2:%3)", note.note().get(), note.file()->filename(), note.line().get());
        case VerificationNote::Code::MISSING_ASSETMAP:
-               return "No ASSETMAP or ASSETMAP.xml was found.";
+               return "No valid ASSETMAP or ASSETMAP.xml was found.";
        case VerificationNote::Code::INVALID_INTRINSIC_DURATION:
                return String::compose("The intrinsic duration of the asset %1 is less than 1 second.", note.note().get());
        case VerificationNote::Code::INVALID_DURATION: