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

Atomic group must not increase stack depth#401

Open
mvorisek opened this issue Mar 22, 2024 · 1 comment
Open

Atomic group must not increase stack depth #401

mvorisek opened this issue Mar 22, 2024 · 1 comment

Comments

@mvorisek
Copy link

mvorisek commented Mar 22, 2024

Currently, when (?: (non-capturing group) is changes to (?> (atomic group), it increases stack usage causing JIT matching to fail with the following error:

JIT stack limit exhausted

This is problematic in deeply recursive regexes as it seems atomic group adds at least +1 stack depth per recursion.

I would expect this to be handled stackless.

Here is an example where we had to reduce atomic group usage to workaround this issue: mvorisek/PHP-CS-Fixer@fbce0f4

@zherczeg
Copy link
Collaborator

Depends on the pattern. Assertions and atomic blocks needs to be reverted when they fail. E.g: (?>(a))b this adds a capturing bracket, which needs to be reverted if b fails to match. Marks, start of match, etc. needs to be reverted as well. So entering to an atomic block / atomic assertion may trigger many variable savings. I remember the engine optimizes some simple cases, but this has limitations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants