Raise PCRE's backtrack_limit for our regex callback usage to avoid

spurious errors on weird input (fixes issue 618).
This commit is contained in:
Thomas Keller 2011-03-03 23:42:21 +01:00
parent 177cf836b4
commit f63bfcb4f6
2 changed files with 20 additions and 6 deletions

View File

@ -34,6 +34,11 @@ class IDF_Template_IssueComment extends Pluf_Template_Tag
function start($text, $request, $echo=true, $wordwrap=true, $esc=true, $autolink=true, $nl2br=false) function start($text, $request, $echo=true, $wordwrap=true, $esc=true, $autolink=true, $nl2br=false)
{ {
// PHP sets the backtrack limit quite low, so some regexes may
// fail unexpectedly on large inputs or weird cornercases (see issue 618)
$pcre_backtrack_limit = ini_get('pcre.backtrack_limit');
ini_set('pcre.backtrack_limit', 10000000);
$this->project = $request->project; $this->project = $request->project;
$this->request = $request; $this->request = $request;
$this->scm = IDF_Scm::get($request->project); $this->scm = IDF_Scm::get($request->project);
@ -67,6 +72,8 @@ class IDF_Template_IssueComment extends Pluf_Template_Tag
} else { } else {
return $text; return $text;
} }
ini_set('pcre.backtrack_limit', $pcre_backtrack_limit);
} }
/** /**

View File

@ -34,6 +34,11 @@ class IDF_Template_Markdown extends Pluf_Template_Tag
function start($text, $request) function start($text, $request)
{ {
// PHP sets the backtrack limit quite low, so some regexes may
// fail unexpectedly on large inputs or weird cornercases (see issue 618)
$pcre_backtrack_limit = ini_get('pcre.backtrack_limit');
ini_set('pcre.backtrack_limit', 10000000);
$this->project = $request->project; $this->project = $request->project;
$this->request = $request; $this->request = $request;
// Replace like in the issue text // Replace like in the issue text
@ -56,6 +61,8 @@ class IDF_Template_Markdown extends Pluf_Template_Tag
$text); $text);
$filter = new IDF_Template_MarkdownPrefilter(); $filter = new IDF_Template_MarkdownPrefilter();
echo $filter->go(Pluf_Text_MarkDown_parse($text)); echo $filter->go(Pluf_Text_MarkDown_parse($text));
ini_set('pcre.backtrack_limit', $pcre_backtrack_limit);
} }
function callbackWikiPageNoName($m) function callbackWikiPageNoName($m)