Fix crash on malformed SubRip file (dcpomatic #1454).
authorCarl Hetherington <cth@carlh.net>
Tue, 29 Jan 2019 22:33:33 +0000 (22:33 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 29 Jan 2019 22:33:33 +0000 (22:33 +0000)
src/subrip_reader.cc
test/subrip_reader_test.cc

index b5d04466bc7bb3e1f9cac167f75f204735b2642b..56256799bc5ae9628a84339dc01662adffb0eab5 100644 (file)
@@ -156,6 +156,9 @@ SubripReader::convert_time (string t)
 
        vector<string> b;
        boost::algorithm::split (b, a[2], boost::is_any_of (","));
+       if (b.size() != 2) {
+               throw SubripError (t, "time in the format h:m:s,ms", _context);
+       }
 
        return Time::from_hms (
                lexical_cast<int> (a[0]),
index c2702c48401c657d0747febb2828f0c1afd8ed1f..d4befacbb1698138d49472eef5938b5c48971987 100644 (file)
@@ -20,6 +20,7 @@
 #include "subrip_reader.h"
 #include "subtitle.h"
 #include "test.h"
+#include "exceptions.h"
 #include "collect.h"
 #include <boost/test/unit_test.hpp>
 #include <boost/filesystem.hpp>
@@ -389,6 +390,20 @@ test (boost::filesystem::path p)
        fclose (f);
 }
 
+static void
+test_throw (boost::filesystem::path p)
+{
+       p = private_test / p;
+       FILE* f = fopen (p.string().c_str(), "r");
+       BOOST_CHECK (f);
+       if (!f) {
+               cerr << p << " not found.\n";
+               return;
+       }
+       BOOST_CHECK_THROW (sub::SubripReader r(f), sub::SubripError);
+       fclose (f);
+}
+
 /** Test of reading some typical .srt files */
 BOOST_AUTO_TEST_CASE (subrip_read_test)
 {
@@ -397,6 +412,7 @@ BOOST_AUTO_TEST_CASE (subrip_read_test)
        test ("Fight.Club.1999.720p.BRRip.x264-x0r.srt");
        test ("EU13.srt");
        test ("Subtitulos_HURTO_eng.srt");
+       test_throw ("subtitulo1.srt");
 }
 
 #define SUB_START(f, t) \