-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
extmod: regex crash due to stack overflow #2451
Comments
Please try to provide minimal example to reproduce the problem, and also elaborate what "crash the board" means, like provide the exact output from the module when running a minimal example. This will allow to investigate the issue sooner rather than later. |
I can reproduce it with a little shorter program. However, shortening the string makes it stop crashing, so I suppose the length has something to do with it. What's interesting, it doesn't crash right away -- I still get the prompt, and then it crashes after a second or so.
|
Sorry, for the missing information. Here the result of different try. First evaluation : running the cript as # main.py
After reboot, the code is executed but the promt is "frozen" Second evaluation :
In this case the promt is "frozen" Third evaluation :
In this case no problem Hope it's better. And thanks for your help |
Confirmed. It's a stack overflow in re1.5/recursiveloop.c:recursiveloop. On unix 64bit the recursiveloop call for the above example uses about 20k of stack. It's because there is a lot of text following the match, which the re engine tries to match against for a longer match than just the "255". If you try a string of similar length but with the @pfalcon this seems like a pretty common thing to use re for so would be nice to make it work with minimal stack usage, but it's not immediately obvious how to do it. |
Although it would harm performance, it might be worth putting a call to mp_stack_check() in recursiveloop to catch any other (more complex) errors like this. |
@dpgeorge : Sure, such need was always anticipated, it's just re1.5 is independent library, so such stack check needs to be added in a reusable/configurable way, which requires some consideration. Now that there're actual reports, I'll look into that. But then it will just error out instead of crashing, still won't work. So, suggestion to people experiencing is to use shorter subject string (in this case, don't match whole HTTP request leader, but match it line by line). |
Stack checking in regex was added in aba1f91 I can confirm that the original code snippet above now raises |
Hello,
The following code crash the board but it works fine with unix micropython :
The board is a chinese nodeMCU :
And micropython is
MicroPython v1.8.4-38-g34e0198-dirty on 2016-09-20; ESP module with ESP8266
Other tests can be found here :
http://forum.micropython.org/viewtopic.php?f=16&t=2416
LAurent_B
The text was updated successfully, but these errors were encountered: