Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 2 compile_tag regular expression problem

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
dmitryg
Smarty Rookie


Joined: 06 Nov 2013
Posts: 5

PostPosted: Wed Nov 06, 2013 11:17 pm    Post subject: Smarty 2 compile_tag regular expression problem Reply with quote

I was asked to check a website which uses Smarty 2. Website dies without giving error.

I tracked the problem to the first preg_match call at Smarty Compiler _compile_tag function. This preg_match call just dies. Doesn't throw error in log or anything.

The website was using very old version of Smarty, version 2.6.12 . I updated today to 2.6.28 released in October 2013. The same error persists.

The website had been working fine for years.

The problem seems to happen for any tag trying to be compiled. For example a very simple one like include file="template_file_name.tpl" .

I inserted a mail() function call to send myself the generated regular expression. It is huge, about 10,000 characters long. I pasted it in a variable in a test script, and used it in a preg_match call in that test script where there is nothing else. Just the hardcoded regex and preg_match call. In this case I get a warning in error_log:

PHP Warning: preg_match() [<a href='function.preg-match'>function.preg-match</a>]: Compilation failed: nothing to repeat at offset 42 .

Can anyone help with this? Any help will be greatly appreciated.

Thanks.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Nov 07, 2013 12:48 am    Post subject: Reply with quote

The PHP pcre.backtrack_limit may be too low for such huge regular expression.

Call ini_set('pcre.backtrack_limit', -1); in the script to switch off any limit.
Back to top
View user's profile Send private message
dmitryg
Smarty Rookie


Joined: 06 Nov 2013
Posts: 5

PostPosted: Thu Nov 07, 2013 2:06 am    Post subject: Reply with quote

Thank you U.Tews.

Looks like this helped. Most pages of website work now. Some pages still die with no error, so I need to check those. It is puzzling that I don't see any error. It's as if the Apache process died for some reason, and no error is logged in error_log.

I made the change you mentioned, and also set pcre.recursion_limit to 300000 (backtrack and recursion were both set to 100000, when I changed backtrack to -1 as you suggested things started working. With recursion I am not sure to use -1, I increased limit)

Thanks again.

U.Tews wrote:
The PHP pcre.backtrack_limit may be too low for such huge regular expression.

Call ini_set('pcre.backtrack_limit', -1); in the script to switch off any limit.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP