-
Notifications
You must be signed in to change notification settings - Fork 463
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
Implement nesting guard to avoid "out of stack space" #2438
Conversation
Note that this limit is not an exact science it depends on various factors, which some are not under our control (compile time or even OS dependent settings on the available stack size) It should fix most common segfault cases though.
|
||
#define NESTING_GUARD(name) \ | ||
LocalOption<size_t> cnt_##name(name, name + 1); \ | ||
if (nestings > MAX_NESTING) throw Exception::NestingLimitError(pstate); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should nestings
be name
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the Macro is called as NESTING_GUARD(nestings)
, therefore it will in turn insert a call to LocalOption<size_t> cnt_nestings(nestings, nestings + 1)
. Meaning it will store the previous value and then increase it by one (reverting once local variable cnt_nesting
goes out of scope).
Sorry, read your statement the reverse way. Yeah, the second line should be name
I guess.
This commit is failing on the 3.4-stable branch, on mingw. Not exactly sure why but I've track it down to the default argument assignment of
See https://ci.appveyor.com/project/sass/libsass/build/1.0.3281 |
Cannot reproduce locally against https://github.com/sass/sass-spec/tree/b744c1036a47681c45b3a2b0eee915ae24166e5e (3.4 seems to be removed in latest specs). Also pretty unlikely to be the cause for the failing at-root-alone-itpl/basic-alone-itpl tests. We also use the same default argument assignment in https://github.com/sass/libsass/pull/2438/files#diff-3f483a2c484893970bcb41dc1c2dac79L29 for quite some time ... |
Issue seems related to the length of the sassc invocation.
|
Debugged it to the main memory corruption: #2484 |
Nice find |
Note that this limit is not an exact science
it depends on various factors, which some are
not under our control (compile time or even OS
dependent settings on the available stack size)
It should fix most common segfault cases though.
Fixing this correctly would need a major refactoring
of the parser to avoid any recursing function calls.
IMO the limit should be pretty safe and it at least
allows somebody to finetune libsass if they need.
Fixes 5+ issues as reported on hackerone