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

Subroutine call backtracking bug #178

Open
Davidebyzero opened this issue Aug 9, 2022 · 0 comments
Open

Subroutine call backtracking bug #178

Davidebyzero opened this issue Aug 9, 2022 · 0 comments

Comments

@Davidebyzero
Copy link

Davidebyzero commented Aug 9, 2022

A pared-down example is matching (12)3 with the regex ((\d|\((?1)\)){2}). It matches (12), but should match (12)3.

PCRE deals with it correctly: https://regex101.com/r/tVAmEt/1
Perl, Ruby/Onigmo, and the Python library mrab-regex also deal with it properly.

The regex that led to the discovery of this bug was the looped substitution s~([*-/]( *(\d++|\((?1)\))){2})(?!\))~($1)~, which adds parentheses to Polish notation.

I have tested and confirmed this to be happening in the latest version of Notepad++, v8.4.4, which uses Boost as its regex engine.

Sample program demonstrating the bug:

#include <boost/regex.hpp>
#include <iostream>
int main()
{
    boost::smatch what;
    if (boost::regex_search(std::string("(12)3"), what, boost::regex(         "((\\d|\\((?1)\\)){2})"        ))) std::cout << what[0] << '\n';
    if (boost::regex_search(std::string("(12)3"), what, boost::regex(       "((?>\\d|\\((?1)\\)){2})"        ))) std::cout << what[0] << '\n';
    if (boost::regex_search(std::string("(12)3"), what, boost::regex("((\\d|\\(((\\d|\\((?1)\\)){2})\\)){2})"))) std::cout << what[0] << '\n';
    return 0;
}

This should print three identical lines of (12)3, but instead prints (12) followed by two lines of (12)3. The third case demonstrates the regex "extruded" to an extra level of depth, by substituting itself in place of (?1).

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

1 participant