From 2ad2d05b0acb99a3222135b06af91deed31f0b00 Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Tue, 27 Feb 2018 11:35:40 +0100 Subject: [PATCH] Fixed star parser, prevent him from going into an infinite loop if an early line starts with a "g" --- modules/io/src/mol/star_parser.cc | 2 ++ modules/io/tests/test_star_parser.cc | 7 +++++++ modules/io/tests/testfiles/broken_global.cif | 1 + 3 files changed, 10 insertions(+) create mode 100644 modules/io/tests/testfiles/broken_global.cif diff --git a/modules/io/src/mol/star_parser.cc b/modules/io/src/mol/star_parser.cc index 4f559b195..214eb626c 100644 --- a/modules/io/src/mol/star_parser.cc +++ b/modules/io/src/mol/star_parser.cc @@ -557,6 +557,8 @@ void StarParser::Parse() case 'g': if (tline.length()>=7 && StringRef("global_", 7)==tline.substr(0, 7)) { this->ParseGlobal(); + } else { + throw IOException("Missing 'global_' control structure"); } break; case '#': diff --git a/modules/io/tests/test_star_parser.cc b/modules/io/tests/test_star_parser.cc index a8ed75451..c4e40fdbd 100644 --- a/modules/io/tests/test_star_parser.cc +++ b/modules/io/tests/test_star_parser.cc @@ -396,6 +396,13 @@ BOOST_AUTO_TEST_CASE(star_broken_data) BOOST_CHECK_THROW(star_p.Parse(), IOException); } +BOOST_AUTO_TEST_CASE(star_broken_global) +{ + std::ifstream s("testfiles/broken_global.cif"); + LoopTestParser star_p(s); + BOOST_CHECK_THROW(star_p.Parse(), IOException); +} + BOOST_AUTO_TEST_CASE(star_missing_data) { std::ifstream s("testfiles/missing_data.cif"); diff --git a/modules/io/tests/testfiles/broken_global.cif b/modules/io/tests/testfiles/broken_global.cif new file mode 100644 index 000000000..0f340e0be --- /dev/null +++ b/modules/io/tests/testfiles/broken_global.cif @@ -0,0 +1 @@ +g lines starting with a 'g' kicked the parser into an infinite loop. -- GitLab