Opened 3 years ago

Closed 3 years ago

Last modified 3 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 Changed 3 years ago by Simon Charette

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 Changed 3 years ago by Simon Charette

Has patch: set

comment:3 Changed 3 years ago by Claude Paroz

Triage Stage: AcceptedReady for checkin

comment:4 Changed 3 years ago by Simon Charette <charette.s@…>

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 Changed 3 years ago by Simon Charette <charette.s@…>

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 Changed 3 years ago by Anders Roos

Very fast fix, thank you everyone!

comment:7 Changed 3 years ago by Simon Charette <charette.s@…>

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 Changed 3 years ago by Simon Charette <charette.s@…>

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