From 97ee50f85090415c830287d38bedd9c9261d6aa2 Mon Sep 17 00:00:00 2001 From: Alon Grinberg Dana Date: Mon, 5 Jun 2017 16:29:33 -0400 Subject: [PATCH 1/2] Added a raise DatabaseError to thermo.py to avoid infinite looping incase a thermo pointer is corrupt --- rmgpy/data/thermo.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rmgpy/data/thermo.py b/rmgpy/data/thermo.py index 68f3426a65..c821468e5a 100644 --- a/rmgpy/data/thermo.py +++ b/rmgpy/data/thermo.py @@ -1738,13 +1738,16 @@ def __addGroupThermoData(self, thermoData, database, molecule, atom): if node is None: raise DatabaseError('Unable to determine thermo parameters for {0}: no data for node {1} or any of its ancestors.'.format(molecule, node0) ) - data = node.data; comment = node.label - while isinstance(data, basestring) and data is not None: - for entry in database.entries.values(): + data = node.data + comment = node.label + while isinstance(data, basestring): + for entry in database.entries.itervalues(): if entry.label == data: data = entry.data comment = entry.label break + else: + raise DatabaseError("Node {0} points to a non-existant group called {1} in database: {2}".format(node.label, data, database.label)) data.comment = '{0}({1})'.format(database.label, comment) # This code prints the hierarchy of the found node; useful for debugging From a408978f3803b3b10d4573d7372104f815248205 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Mon, 28 Aug 2017 15:37:34 -0400 Subject: [PATCH 2/2] Add Loop Counter to __addGroupThermoData Prevents the while loop from repeating indefinitely. --- rmgpy/data/thermo.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rmgpy/data/thermo.py b/rmgpy/data/thermo.py index c821468e5a..cfacafd250 100644 --- a/rmgpy/data/thermo.py +++ b/rmgpy/data/thermo.py @@ -1740,7 +1740,14 @@ def __addGroupThermoData(self, thermoData, database, molecule, atom): data = node.data comment = node.label + loop_count = 0 while isinstance(data, basestring): + loop_count += 1 + if loop_count > 100: + raise DatabaseError("Maximum iterations reached while following thermo group data pointers. A circular" + " reference may exist. Last node was {0} pointing to group called {1} in " + "database {2}".format(node.label, data, database.label)) + for entry in database.entries.itervalues(): if entry.label == data: data = entry.data