Skip to content

Traceback formatting in Python 3.6 32-bit Windows causes hang #1162

@samuelchen

Description

@samuelchen

Hi,

I was facing an issue when using incorrect variable name in Flask template. An dash "-" linked variable name in template cause Flask to hang without throwing any exception.

At first I doubt it's Jinja issue but I found Jinja raised the exception and Werkzeug handled it.

Eventually, I found an endless loop in Python\Lib\traceback.py to walk trackback stacks. The
trackbacks are stored in a link which nodes point to next. In flask\templating.py,
flask\app.py and werkzeug\debug\tbtools.py, the exception was catched. In
handle_exception() of flask\app.py, Werkzeug wants to log it and print it out.

The trackback link has looped reference as below picture.

Image

Hope its helpful. Thanks you.

Expected Behavior

Render variable out or throw exception out.

import sys
from flask import Flask, request, render_template_string, make_response, url_for, redirect

### {{ font-size }} causes app hang ###

app = Flask(__name__)

template_page = '''
<html>
<head>
<meta charset="{{ encoding }}" />
<meta http-equiv="content-type" content="text/html; charset={{ encoding }}" />
<style type="text/css">
  body, pre, p, div, input, h1,h2,h3,h4,h5 {
    font-family : Consolas, Courier New;
  }
</style>
</head>
<body>
    <div id="wrapper" style="font-size:{{ font-size }}em">
        {{ content | safe }}
    </div>
</body>'''


@app.route('/', methods=['GET'])
def index():
    context = {
        "encoding": 'utf-8',
        "font-size": 0.9,
        "content": 'hello flask'
    }
    resp = make_response(render_template_string(template_page, **context))
    resp.headers['Content-Type'] = 'text/html; charset=utf-8'
    return resp


if __name__ == "__main__":
    # app.run(debug=True, host='0.0.0.0', port=8080)

    app.run()

Actual Behavior

App hangs.

N/A

Environment

  • Python version: 3.6.8
  • Flask version: 1.1.1
  • Werkzeug version: 0.16.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions