Bv2.1 7.2.1: Check size of timed text asset is not larger than 115MB.
authorCarl Hetherington <cth@carlh.net>
Sun, 13 Dec 2020 22:03:22 +0000 (23:03 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 17 Jan 2021 19:13:22 +0000 (20:13 +0100)
src/verify.cc
src/verify.h
test/verify_test.cc

index 9cfcd4b9c38657bad4fb6a0562cb3844db3aa902..3c36e8f660e812938a9c791a0bb21ea5696dc7aa 100644 (file)
@@ -659,6 +659,13 @@ verify_subtitle_asset (
                if (smpte->language()) {
                        verify_language_tag (*smpte->language(), notes);
                }
+               if (boost::filesystem::file_size(*asset->file()) > 115 * 1024 * 1024) {
+                       notes.push_back (
+                               VerificationNote(
+                                       VerificationNote::VERIFY_BV21_ERROR, VerificationNote::TIMED_TEXT_ASSET_TOO_LARGE_IN_BYTES, *asset->file()
+                                       )
+                               );
+               }
        }
 }
 
@@ -857,6 +864,8 @@ dcp::note_to_string (dcp::VerificationNote note)
                return "3D 4K DCPs are not allowed by Bv2.1";
        case dcp::VerificationNote::CLOSED_CAPTION_XML_TOO_LARGE_IN_BYTES:
                return String::compose("The XML for the closed caption asset %1 is longer than the 256KB maximum required by Bv2.1", note.file()->filename());
+       case dcp::VerificationNote::TIMED_TEXT_ASSET_TOO_LARGE_IN_BYTES:
+               return String::compose("The total size of the timed text asset %1 is larger than the 115MB maximum required by Bv2.1", note.file()->filename());
        }
 
        return "";
index 24c19b2b375916608bc609c8496b7fa428188818..3b5dafac37e76cc3a552692e07f076badbf7ce42 100644 (file)
@@ -104,6 +104,8 @@ public:
                PICTURE_ASSET_4K_3D,
                /** A closed caption's XML file is larger than 256KB [Bv2.1_7.2.1] */
                CLOSED_CAPTION_XML_TOO_LARGE_IN_BYTES,
+               /** Any timed text asset's total files is larger than 115MB [Bv2.1_7.2.1] */
+               TIMED_TEXT_ASSET_TOO_LARGE_IN_BYTES,
        };
 
        VerificationNote (Type type, Code code)
index cf00202b8c6e8b2beeba0dd1bb4fa545fecfda51..74fd81e86be54fbde7bba45e4ec7e6894f6d30d2 100644 (file)
@@ -1210,3 +1210,77 @@ BOOST_AUTO_TEST_CASE (verify_closed_caption_xml_too_large)
        BOOST_CHECK_EQUAL (notes.front().code(), dcp::VerificationNote::CLOSED_CAPTION_XML_TOO_LARGE_IN_BYTES);
 }
 
+
+static
+shared_ptr<dcp::SMPTESubtitleAsset>
+make_large_subtitle_asset (boost::filesystem::path font_file)
+{
+       shared_ptr<dcp::SMPTESubtitleAsset> asset(new dcp::SMPTESubtitleAsset());
+       dcp::ArrayData big_fake_font(1024 * 1024);
+       big_fake_font.write (font_file);
+       for (int i = 0; i < 116; ++i) {
+               asset->add_font (dcp::String::compose("big%1", i), big_fake_font);
+       }
+       return asset;
+}
+
+
+template <class T>
+void
+verify_timed_text_asset_too_large (string name)
+{
+       boost::filesystem::path const dir = boost::filesystem::path("build/test") / name;
+       prepare_directory (dir);
+       shared_ptr<dcp::SMPTESubtitleAsset> asset = make_large_subtitle_asset (dir / "font.ttf");
+       asset->add (
+               shared_ptr<dcp::Subtitle>(
+                       new dcp::SubtitleString(
+                               optional<string>(),
+                               false,
+                               false,
+                               false,
+                               dcp::Colour(),
+                               42,
+                               1,
+                               dcp::Time(0, 24, 24),
+                               dcp::Time(20, 24, 24),
+                               0,
+                               dcp::HALIGN_CENTER,
+                               0,
+                               dcp::VALIGN_CENTER,
+                               dcp::DIRECTION_LTR,
+                               "Hello",
+                               dcp::NONE,
+                               dcp::Colour(),
+                               dcp::Time(),
+                               dcp::Time()
+                               )
+                       )
+               );
+       asset->write (dir / "subs.mxf");
+
+       shared_ptr<T> reel_asset(new T(asset, dcp::Fraction(24, 1), 16 * 24, 0));
+       shared_ptr<dcp::Reel> reel(new dcp::Reel());
+       reel->add (reel_asset);
+       shared_ptr<dcp::CPL> cpl(new dcp::CPL("hello", dcp::FEATURE));
+       cpl->add (reel);
+       shared_ptr<dcp::DCP> dcp(new dcp::DCP(dir));
+       dcp->add (cpl);
+       dcp->write_xml (dcp::SMPTE);
+
+       vector<boost::filesystem::path> dirs;
+       dirs.push_back (dir);
+       list<dcp::VerificationNote> notes = dcp::verify (dirs, &stage, &progress, xsd_test);
+       BOOST_REQUIRE_EQUAL (notes.size(), 1U);
+       BOOST_CHECK_EQUAL (notes.front().type(), dcp::VerificationNote::VERIFY_BV21_ERROR);
+       BOOST_CHECK_EQUAL (notes.front().code(), dcp::VerificationNote::TIMED_TEXT_ASSET_TOO_LARGE_IN_BYTES);
+}
+
+
+BOOST_AUTO_TEST_CASE (verify_subtitle_asset_too_large)
+{
+       verify_timed_text_asset_too_large<dcp::ReelSubtitleAsset>("verify_subtitle_asset_too_large");
+       verify_timed_text_asset_too_large<dcp::ReelClosedCaptionAsset>("verify_closed_caption_asset_too_large");
+}
+
+