From b60fd2d2b68be2a2fcfe067fd5a96af5b08e3a8d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 6 Dec 2019 17:40:25 +0100 Subject: Use regex and check in CPL. --- src/verify.cc | 50 ++++++++++++++++++++++++++++++++------------------ src/verify.h | 2 ++ 2 files changed, 34 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/verify.cc b/src/verify.cc index f4b89afd..032a3f39 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -39,8 +39,10 @@ #include "reel_sound_asset.h" #include "exceptions.h" #include "compose.hpp" +#include "raw_convert.h" #include #include +#include #include #include #include @@ -96,37 +98,44 @@ verify_asset (shared_ptr dcp, shared_ptr reel_mxf, function res; + if (!regex_match (date, res, ex, boost::match_default)) { return false; } - - if (!boost::algorithm::starts_with(id, "urn:uuid:")) { + int const month = dcp::raw_convert(res[1].str()); + if (month < 1 || month > 12) { return false; } - - if (id[17] != '-' || id[22] != '-' || id[27] != '-' || id[32] != '-') { + int const day = dcp::raw_convert(res[2].str()); + if (day < 1 || day > 31) { return false; } - - if (!hex(id.substr(9, 8)) || !hex(id.substr(18, 4)) || !hex(id.substr(23, 4)) || !hex(id.substr(28, 4)) || !hex(id.substr(33, 8))) { + if (dcp::raw_convert(res[3].str()) > 23) { + return false; + } + if (dcp::raw_convert(res[4].str()) > 59) { + return false; + } + if (dcp::raw_convert(res[5].str()) > 59) { + return false; + } + if (dcp::raw_convert(res[6].str()) > 23) { + return false; + } + if (dcp::raw_convert(res[7].str()) > 59) { return false; } - return true; } @@ -158,6 +167,9 @@ dcp::verify (vector directories, function is malformed"))); } + if (!good_date(cpl_doc.string_child("IssueDate"))) { + notes.push_back (VerificationNote(VerificationNote::VERIFY_ERROR, VerificationNote::Code::BAD_DATE, string("CPL is malformed"))); + } /* Check that the CPL's hash corresponds to the PKL */ BOOST_FOREACH (shared_ptr i, dcp->pkls()) { @@ -252,7 +264,9 @@ dcp::note_to_string (dcp::VerificationNote note) case dcp::VerificationNote::MISMATCHED_STANDARD: return "The DCP contains both SMPTE and Interop parts."; case dcp::VerificationNote::BAD_URN_UUID: - return "There is a badly formed urn:uuid."; + return "There is a badly-formed urn:uuid."; + case dcp::VerificationNote::BAD_DATE: + return "There is a badly-formed date."; } return ""; diff --git a/src/verify.h b/src/verify.h index 1403797c..4007f8fb 100644 --- a/src/verify.h +++ b/src/verify.h @@ -77,6 +77,8 @@ public: MISMATCHED_STANDARD, /** A urn:uuid ID is badly formed */ BAD_URN_UUID, + /** A date is badly formed */ + BAD_DATE, }; VerificationNote (Type type, Code code) -- cgit v1.2.3