Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(817)

Unified Diff: src/ast/ast.cc

Issue 1522353002: [regexp] break recursion in mutually recursive capture/back references. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/ast.h ('k') | src/parsing/parser.cc » ('j') | test/mjsunit/regexp.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/ast.cc
diff --git a/src/ast/ast.cc b/src/ast/ast.cc
index 3c8eb1ff7f1c109e4e9ee83824bc551815d2f55b..0fd1531387c62cb644fa383acab2c2e392dd0d1d 100644
--- a/src/ast/ast.cc
+++ b/src/ast/ast.cc
@@ -926,6 +926,35 @@ bool RegExpCapture::IsAnchoredAtEnd() {
}
+int RegExpBackReference::max_match() {
erikcorry 2015/12/15 08:09:19 Alternative simpler implementation is to return kI
+ switch (max_match_) {
+ case kRecursionMarker:
+ // The back reference references a capture that references this back
+ // reference, leading to a recursion, e.g. /(\2)(\1)/.
+ // Such captures cannot be satisfied and have the length 0.
+ max_match_ = 0;
+ break;
+ case kUninitialized:
+ // The max match length of a back reference is the length of the capture.
+ if (capture_->body()) {
+ // Mark this back reference to break possible recursion before
+ // descending into the capture.
+ max_match_ = kRecursionMarker;
+ max_match_ = capture_->max_match();
+ } else {
+ // If the capture has no body, it has not been parsed and does not
+ // exist. Hence the length is 0.
+ max_match_ = 0;
+ }
+ break;
+ default:
+ // max_match_ has already been found.
+ break;
+ }
+ return max_match_;
+}
+
+
// Convert regular expression trees to a simple sexp representation.
// This representation should be different from the input grammar
// in as many cases as possible, to make it more difficult for incorrect
« no previous file with comments | « src/ast/ast.h ('k') | src/parsing/parser.cc » ('j') | test/mjsunit/regexp.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698