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:35:24 +0000 |
| commit | 030740d3c905e1e13c58e5e45f698ae2f9513ba1 (patch) | |
| tree | 924602cd371eb95c237197ebc397362563686c6a | |
| parent | eb88d114acaf095ff49d83f4fcaa28d824fb3b14 (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 45da3ab..3a08c3b 100644 --- a/src/subrip_reader.cc +++ b/src/subrip_reader.cc @@ -155,6 +155,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 604f52a..283b607 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> @@ -372,6 +373,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) { @@ -380,6 +395,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) \ |
