Permalink
Browse files

infinite loop checks

  • Loading branch information...
1 parent 1e6b177 commit 7d7a79ef21296b9a55d710850691779dbc0b4d3a @mjy committed Apr 10, 2010
Showing with 16 additions and 3 deletions.
  1. +16 −3 lib/parser.rb
View
@@ -84,7 +84,11 @@ def parse_taxa_blk
# need to not ignore to test against
parse_dimensions if @lexer.peek(NexusParser::Tokens::Dimensions)
+ inf = 0
while true
+ inf += 1
+ raise (ParserError,"Either you have a gazillion taxa or more likely the parser is caught in an infinite loop trying to parser taxon labels. Check for double single quotes in this block.") if inf > 100000
+
if @lexer.peek(NexusParser::Tokens::EndBlk)
@lexer.pop(NexusParser::Tokens::EndBlk)
break
@@ -113,7 +117,12 @@ def parse_taxa_blk
end
def parse_characters_blk
+
+ inf = 0
while true
+ inf += 1
+ raise (ParserError,"Either you have a gazillion characters or more likely the parser is caught in an infinite loop trying to parser character data. Check for double single quotes in this block.") if inf > 100000
+
if @lexer.peek(NexusParser::Tokens::EndBlk) # we're at the end of the block, exit after geting rid of the semi-colon
break
else
@@ -171,8 +180,12 @@ def check_initialization_of_ntax_nchar
def parse_chr_state_labels
@lexer.pop(NexusParser::Tokens::CharStateLabels)
-
+
+ inf = 0
while true
+ inf += 1
+ raise (ParserError,"Either you have a gazillion character state labels or more likely the parser is caught in an infinite loop while trying to parser character state labels. Check for double single quotes in this block.") if inf > 100000
+
if @lexer.peek(NexusParser::Tokens::SemiColon)
break
else
@@ -232,10 +245,10 @@ def parse_notes_blk
# IMPORTANT - we don't parse the (CM <note>), we just strip the "(CM" ... ")" bit for now in NexusParser::Note
@vars = {}
- inf = 0
+ inf = 0 # a crude iteration checker
while true
inf += 1
- raise "Either you have a gazillion notes or more likely parser is caught in an infinite loop inside parse_notes_block" if inf > 100000
+ raise (ParserError,"Either you have a gazillion notes or more likely parser is caught in an infinite loop inside the Begin Notes block. Check for double single quotes in this block.") if inf > 100000
if @lexer.peek(NexusParser::Tokens::EndBlk)
@lexer.pop(NexusParser::Tokens::EndBlk)
@builder.add_note(@vars) # one still left to add

0 comments on commit 7d7a79e

Please sign in to comment.