diff options
Diffstat (limited to 'django')
| -rw-r--r-- | django/utils/encoding.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py index 999ffae19a..a29ef2be58 100644 --- a/django/utils/encoding.py +++ b/django/utils/encoding.py @@ -237,13 +237,16 @@ def repercent_broken_unicode(path): we need to re-percent-encode any octet produced that is not part of a strictly legal UTF-8 octet sequence. """ - try: - path.decode('utf-8') - except UnicodeDecodeError as e: - repercent = quote(path[e.start:e.end], safe=b"/#%[]=:;$&()+,!?*@'~") - path = repercent_broken_unicode( - path[:e.start] + force_bytes(repercent) + path[e.end:]) - return path + while True: + try: + path.decode('utf-8') + except UnicodeDecodeError as e: + # CVE-2019-14235: A recursion shouldn't be used since the exception + # handling uses massive amounts of memory + repercent = quote(path[e.start:e.end], safe=b"/#%[]=:;$&()+,!?*@'~") + path = path[:e.start] + force_bytes(repercent) + path[e.end:] + else: + return path def filepath_to_uri(path): |
