Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#26536 closed Bug (fixed)

Stack overflow in template rendering when using django.template.loaders.cached.Loader

Reported by: Anders Roos Owned by: nobody
Component: Template system Version: 1.9
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you have two template files with the same name except one is prefixed with a dash '-' where one is including the other, you will get a stack overflow.

For example if the main template named example.html looks like this:

{% include '-example.html' %}

This bug is in django.template.loaders.cached.Loader and only happens if it is used.

I believe the bug is caused by the strip('-') when building the cache key at django/template/loaders/cached.py:103 (in Loader.cache_key):

    return ("%s-%s-%s" % (template_name, skip_prefix, dirs_prefix)).strip('-')

Change History (8)

comment:1 by Simon Charette, 9 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

This is a regression introduced by fc2147152637e21bc73f991b50fa06254af02739.

Using '-'.join(filter(bool, [template_name, skip_prefix, dirs_prefix])) instead should fix the issue.

comment:2 by Simon Charette, 9 years ago

Has patch: set

comment:3 by Claude Paroz, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Simon Charette <charette.s@…>, 9 years ago

Resolution: fixed
Status: newclosed

In bd145e7:

Fixed #26536 -- Preserved leading dashes of the cached template loader keys.

Thanks Anders Roos for the report.

comment:5 by Simon Charette <charette.s@…>, 9 years ago

In a06fa6e7:

[1.9.x] Fixed #26536 -- Preserved leading dashes of the cached template loader keys.

Thanks Anders Roos for the report.

Backport of bd145e7209a0e628cced10384bd6f62d65c0f211 from master

comment:6 by Anders Roos, 9 years ago

Very fast fix, thank you everyone!

comment:7 by Simon Charette <charette.s@…>, 9 years ago

In 207c5b4:

Fixed #26603 -- Forced lazy template names to text when computing cache key.

Refs #26536.

Thanks Sylvain Fankhauser for the very detailed report.

comment:8 by Simon Charette <charette.s@…>, 9 years ago

In 6a67dce:

[1.9.x] Fixed #26603 -- Forced lazy template names to text when computing cache key.

Refs #26536.

Thanks Sylvain Fankhauser for the very detailed report.

Backport of 207c5b4acd410dd39bac31457dae26a0d15b8b93 from master

Note: See TracTickets for help on using tickets.
Back to Top