-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
When I use **while** not stop in the views #1155
Comments
There is actually an endless-loop bug in template parsing, so the template never gets to the point the while loop is run. The parsing already hangs up. Interesting! |
It's the img-tag in the while loop. The unbalanced single-quotes in |
Thanks!! You saved my day. |
It would be nice if the bottle.py informs this SyntaxError. |
looks like we have a runaway regular expressions in the template parsing code. It is not an endless loop or a bug in bottle itself, but a regular expression that is extremely slow for certain inputs (catastrophic backtracking problem). Hmm, that's not that easy to fix. |
We could make a method of throwing a timeout exception when regular expressions take a long time to respond, so it would be easier to identify the problem. I must have spent about four hours rebuilding the loop code and trying to make it work, when in fact the problem was one more quote in that part of the code. I got stuck on this because the last code I had typed was while loop, after that it stopped working, but I didn't realize the real problem. |
Unfortunately, python If Bottle or SimpleTemplate would be a normal library I'd immediately start fixing this issue, but Bottle is a micro-framework and the template parser is less than 200 lines of code. Rewriting it to catch this edge case would significantly increase its size and complexity. I'm not sure this can be done without a complete rewrite of most of its logic :/ Also, this is the first time this bug is reported in more than 10 years of project history. For this reason, I currently tend to mark this as "won't fix" until someone comes up with an acceptable solution. That said, these bugs can be found quite easily with a debugger or |
Can you point out which regular expression in |
I think I found it. I had an outdated version of
The issue on line 349 corresponds to #1194, and I believe the issue on line 3020 is this issue. The line itself is: _hsplit = re.compile('(?:(?:"((?:[^"\\\\]+|\\\\.)*)")|([^;,=]+))([;,=]?)').findall Again we have catastrophic backtracking in the >>> _hsplit = re.compile('(?:(?:"((?:[^"\\\\]+|\\\\.)*)")|([^;,=]+))([;,=]?)').findall
>>> _hsplit('"' + '.' * 64 + ';')
... Spins ... I'm not sure about the exact logic behind the alternation or branch ( |
The issue is very similar to #1194: The expression should match a quotes string up until the first non-escaped quote. Similar logic, similar pattern, same backtracking issue. Maybe the same fix also works here: Removing the inner repetition. I'll have to test that. |
Oh, that's bad. The _hsplit issue is not related to this bug (which is triggered by the expression used to parse templates), but from the header parser and MIGHT be exploitable (DOS) by an attacker. |
Phew, that was close. Fortunately, |
Regarding this issue, I think it is the line
Again, the inner |
Yes, that's it. This change solves the issue. Hurray \o/ |
Nice! For the record, Dlint doesn't know how to find the |
Related to bottlepy#1194 This backports the patch from 332215b to the 0.12 release branch.
Related to bottlepy#1194 This backports the patch from 332215b to the 0.12 release branch. This fix can be validated using the following repl commands: >>> import bottle >>> bottle.template("""<img src="{{usar_webp(''/static/images/branco400.jpg')}}" alt="Sem imagem"/>""")
Related to bottlepy#1194 This backports the patch from 332215b to the 0.12 release branch. This fix can be validated using the following repl commands: >>> import bottle >>> bottle.template("""<img src="{{usar_webp(''/static/images/branco400.jpg')}}" alt="Sem imagem"/>""")
Hello guys, I'm trying to use the while statement in views, but I don't stop, even if the condition is met, look this:
In this code I try use the while instruction to show in minimal three images for the slide layout. But never stops, anybody know solve this?
The text was updated successfully, but these errors were encountered: