summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2020-12-17 08:03:20 +0100
committerGeorg Brandl <georg@python.org>2020-12-17 08:03:20 +0100
commita56ed8a1f2eb0db14aad50cb7e4eaaf7f2f0d3b3 (patch)
treeea548a3807caee51edceec97e9bb301117fc3882
parent7958cd6c53215ac2caeb6812aaeab5e8029a43ad (diff)
downloadpygments-git-a56ed8a1f2eb0db14aad50cb7e4eaaf7f2f0d3b3.tar.gz
Limit recursion with nesting Ruby heredocs
fixes #1638
-rw-r--r--CHANGES1
-rw-r--r--pygments/lexers/crystal.py7
-rw-r--r--pygments/lexers/ruby.py7
3 files changed, 11 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index c8b5dfbb..5e133d8b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,7 @@ Version 2.7.4
- Fixed infinite loop in SML lexer (#1625)
- Fixed backtracking string regexes in JavaScript/TypeScript lexers (#1637)
+- Limit recursion with nesting Ruby heredocs (#1638)
Version 2.7.3
diff --git a/pygments/lexers/crystal.py b/pygments/lexers/crystal.py
index cf051536..05171c9c 100644
--- a/pygments/lexers/crystal.py
+++ b/pygments/lexers/crystal.py
@@ -57,8 +57,11 @@ class CrystalLexer(ExtendedRegexLexer):
ctx.pos = match.start(5)
ctx.end = match.end(5)
- # this may find other heredocs
- yield from self.get_tokens_unprocessed(context=ctx)
+ # this may find other heredocs, so limit the recursion depth
+ if len(heredocstack) < 100:
+ yield from self.get_tokens_unprocessed(context=ctx)
+ else:
+ yield ctx.pos, String.Heredoc, match.group(5)
ctx.pos = match.end()
if outermost:
diff --git a/pygments/lexers/ruby.py b/pygments/lexers/ruby.py
index e16cd711..d1ae5aff 100644
--- a/pygments/lexers/ruby.py
+++ b/pygments/lexers/ruby.py
@@ -57,8 +57,11 @@ class RubyLexer(ExtendedRegexLexer):
ctx.pos = match.start(5)
ctx.end = match.end(5)
- # this may find other heredocs
- yield from self.get_tokens_unprocessed(context=ctx)
+ # this may find other heredocs, so limit the recursion depth
+ if len(heredocstack) < 100:
+ yield from self.get_tokens_unprocessed(context=ctx)
+ else:
+ yield ctx.pos, String.Heredoc, match.group(5)
ctx.pos = match.end()
if outermost: