@@ -53,6 +53,7 @@ namespace boost
53
53
54
54
namespace read_graphviz_detail
55
55
{
56
+ static const long max_subgraph_nesting_level = 255 ;
56
57
struct token
57
58
{
58
59
enum token_type
@@ -527,6 +528,7 @@ namespace read_graphviz_detail
527
528
std::map< subgraph_name, subgraph_info > subgraphs;
528
529
std::string current_subgraph_name;
529
530
int sgcounter; // Counter for anonymous subgraphs
531
+ long sgnesting_level;
530
532
std::set< std::pair< node_name, node_name > >
531
533
existing_edges; // Used for checking in strict graphs
532
534
@@ -538,7 +540,7 @@ namespace read_graphviz_detail
538
540
subgraph_member_list& current_members () { return current ().members ; }
539
541
540
542
parser (const std::string& gr, parser_result& result)
541
- : the_tokenizer(gr), lookahead(), r(result), sgcounter(0 )
543
+ : the_tokenizer(gr), lookahead(), r(result), sgcounter(0 ), sgnesting_level( 0 )
542
544
{
543
545
current_subgraph_name = " ___root___" ;
544
546
current () = subgraph_info (); // Initialize root graph
@@ -803,6 +805,10 @@ namespace read_graphviz_detail
803
805
return name;
804
806
}
805
807
subgraph_name old_sg = current_subgraph_name;
808
+ if (++sgnesting_level > max_subgraph_nesting_level)
809
+ {
810
+ error (" Exceeded maximum subgraph nesting level" );
811
+ }
806
812
current_subgraph_name = name;
807
813
if (first_token.type != token::left_brace)
808
814
{
@@ -817,6 +823,7 @@ namespace read_graphviz_detail
817
823
else
818
824
error (" Wanted right brace to end subgraph" );
819
825
current_subgraph_name = old_sg;
826
+ sgnesting_level -= 1 ;
820
827
return name;
821
828
}
822
829
0 commit comments