diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2014-03-29 19:44:11 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2014-03-29 19:47:47 +0100 |
| commit | 18b2c03ea31027d2f102df3c6b173cb6e63da52d (patch) | |
| tree | 1f80f5accc7db721290d218635a58cf99b3d7ccf | |
| parent | c139e3e0a0d190b9b06e0cf2ec0c0c409ca978c3 (diff) | |
[1.7.x] Increased memoization cache size for language codes.
There may be more than 100 (default maxsize) commonly seen xx-yy values
on some sites. The additional memory consumption isn't significant.
Also added a comment explaining why this cache must have a maxsize.
Backport of f356b6e from master.
| -rw-r--r-- | django/utils/translation/trans_real.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index bf6ad7ee95..6bbdbe5f20 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -389,12 +389,16 @@ def all_locale_paths(): return [globalpath] + list(settings.LOCALE_PATHS) -@lru_cache.lru_cache() +@lru_cache.lru_cache(maxsize=1000) def check_for_language(lang_code): """ Checks whether there is a global language file for the given language code. This is used to decide whether a user-provided language is available. + + lru_cache should have a maxsize to prevent from memory exhaustion attacks, + as the provided language codes are taken from the HTTP request. See also + <https://www.djangoproject.com/weblog/2007/oct/26/security-fix/>. """ # First, a quick check to make sure lang_code is well-formed (#21458) if not language_code_re.search(lang_code): |
