Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser diverges instead of failing on ill-formed raw blocks #1156

Closed
thumphries opened this issue Dec 17, 2015 · 4 comments
Closed

Parser diverges instead of failing on ill-formed raw blocks #1156

thumphries opened this issue Dec 17, 2015 · 4 comments
Labels

Comments

@thumphries
Copy link

Hello,

{{{{regular}}}} {{{{ expressions }}}} {{{{/expressions}}}} {{{{/  regular}}}}

Handlebars will diverge and eventually run out of memory on the above inputs. The culprit is the space before regular in the outer raw close. In the lexer, this seems like input that should be reasonably quickly rejected by https://github.com/wycats/handlebars.js/blob/master/src/handlebars.l#L54, so that makes me think the greedy match immediately below that is also culpable.

Note that whenever the closing raw block is invalid after a correct {{{{/ it seems to do the same thing:

{{{{regular}}}} {{{{ expressions }}}} {{{{/expressions}}}}  {{{{/awoeifjawoiefjaoiwejfoaiwejfio}}}
{{{{regular}}}} {{{{ expressions }}}} {{{{/expressions}}}}  {{{{/awoeifjawoiefjaoiwejfoaiwe
{{{{regular}}}} {{{{ expressions }}}} {{{{/expressions}}}}  {{{{/mary had a little lamb
@thumphries
Copy link
Author

The nesting also appears to be irrelevant, i.e. it still crashes on

{{{{a}}}}{{{{/ a}}}}
==== JS stack trace =========================================

Security context: 0x1bc374d44a49 <JS Object>
    1: anonymous [/usr/local/lib/node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js:~11] [pc=0x2e09dbfa2e8a] (this=0x35dfe0dfa821 <an Object with map 0x10a715869621>,yytext=0x1bc374dfdf89 <String[0]: >,yyleng=0,yylineno=0,yy=0x3a967ba8cdc9 <an Object with map 0x10a715869411>,yystate=10,$$=0x1bc374dfdf49 <JS Array[5]>,_$=0x1bc374dfdf69 <JS Array[5]>)
    2: parse [/usr/local/lib/node...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

@damncabbage
Copy link

Confirmed here with this jsfiddle: https://jsfiddle.net/9D88g/50/

screen shot 2016-02-18 at 6 33 22 pm

(Don't click the link unless you want the browser to chew up a bunch of memory.)

@mootari
Copy link

mootari commented Jan 13, 2018

Also running out of memory with:

{{{{raw}}}} {{{{/raw }}}}

@nknapp
Copy link
Collaborator

nknapp commented Apr 5, 2020

Seems to be fixed with #1578

@nknapp nknapp closed this as completed Apr 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants