diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-01-29 22:33:33 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-01-29 22:33:33 +0000 |
| commit | 23d4d5df719e020011686ff9225845ae360f408e (patch) | |
| tree | 84e2b40b72b602c86d33e6711d7ac45b7a79fc2f | |
| parent | 149f2cab4d14c4bc801c168f64d259c1f67deb9a (diff) | |
Fix crash on malformed SubRip file (dcpomatic #1454).
| -rw-r--r-- | src/subrip_reader.cc | 3 | ||||
| -rw-r--r-- | test/subrip_reader_test.cc | 16 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/subrip_reader.cc b/src/subrip_reader.cc index b5d0446..5625679 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -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]), diff --git a/test/subrip_reader_test.cc b/test/subrip_reader_test.cc index c2702c4..d4befac 100644 --- a/test/subrip_reader_test.cc +++ b/test/subrip_reader_test.cc @@ -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) \ |
