safe_range has previously used xrange to get the length of a sequence.
rng = xrange(*args)
if len(rng) > MAX_RANGE:
raise OverflowError('range too big, maximum size for range is %d' %
MAX_RANGE)
However since porting to Python 3 it uses range which behaves differently in Python 2 and 3. On Python 2 it will try to generate the whole sequence in memory before measuring the length -- which can cause an out of memory error.
Expected Behavior
safe_range(100000000000) should raise an OverflowError
Actual Behavior
safe_range(100000000000) attempts to generate a huge list in memory
Template Code
{%for n in range(100000000000) %}{{n}}{% endfor %}
Your Environment
- Python version: 2.7
- Jinja version: 2.10
safe_rangehas previously usedxrangeto get the length of a sequence.However since porting to Python 3 it uses
rangewhich behaves differently in Python 2 and 3. On Python 2 it will try to generate the whole sequence in memory before measuring the length -- which can cause an out of memory error.Expected Behavior
safe_range(100000000000) should raise an
OverflowErrorActual Behavior
safe_range(100000000000) attempts to generate a huge list in memory
Template Code
Your Environment