-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix #58 #64
Fix #58 #64
Conversation
Do note that this only fixes the hanging. c_formatter_42 will still insert |
Can you add a test with pytest-timeout? @pytest.mark.timeout(60)
def test_foo():
pass |
@cacharle For the whole run_all procedure or just for line_break? |
Just for the example we know was infinite before your fix for now (so only But I see you can set a global timeout in the [pytest]
timeout = 20 |
@cacharle Been trying to make it work for the last 30 minutes but it seems that pytest-timeout suffers from an issue with (at least) Python 3.10: pytest-dev/pytest-timeout#113 |
Works fine for me with python3.10
with the following code: import time
@pytest.mark.timeout(2)
def test_foo():
time.sleep(10000) |
@cacharle Alright well perhaps it's a Windows problem then. I'll push the test |
WSL 👀👀👀👀👀 |
Yeah I use WSL for 42 projects, I'm just too lazy to setup all my Python env on there lol |
Fix #58 thanks to ChatGPT
Prompt
You are a Python expert. Your task is to detect the catastrophic backtracking error in a regex for a C formatter program.
If you cannot find the catastrophic backtracking error, it's okay to say so.
Here are our regex helpers:
And here is the regex with the catastrophic backtracking error:
The regex you've provided indeed contains a potential catastrophic backtracking issue. The problematic part is the
(.\|\s)*?
section within the regex. This part can lead to catastrophic backtracking when trying to match certain inputs, especially if the input contains a long sequence of characters followed by a semicolon.Here's why it's problematic:
(.\|\s)*?
attempts to match any character or whitespace zero or more times in a non-greedy manner. The problem is that when the regex engine encounters a character that doesn't match, it will backtrack and try different ways of matching characters and whitespace until it either succeeds or exhausts all possibilities. This can lead to an exponential number of possible paths that the engine explores, causing significant slowdown or even freezing on certain inputs.To avoid this issue, you can use a more specific pattern to match the content within the parentheses in a safer way. Here's a modified version of the regex that should help avoid catastrophic backtracking:
r"^(static\s+)?{type}\s+{name}\([^)]*?\);"
In this modified regex,
[^)]*?
is used to match any sequence of characters except a closing parenthesis. This pattern ensures that the regex engine won't get stuck in catastrophic backtracking scenarios.