From 5c63b3e5a797102d915e1683971517f747a28013 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 3 Aug 2016 12:46:57 -0400 Subject: [PATCH] Fixed #27005 -- Fixed crash if request.META[''CONTENT_LENGTH']=''. --- django/http/request.py | 2 +- docs/releases/1.10.1.txt | 3 +++ tests/requests/test_data_upload_settings.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/http/request.py b/django/http/request.py index 84230be6e05..1dedf5d8990 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -264,7 +264,7 @@ class HttpRequest(object): # Limit the maximum request data size that will be handled in-memory. if (settings.DATA_UPLOAD_MAX_MEMORY_SIZE is not None and - int(self.META.get('CONTENT_LENGTH', 0)) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE): + int(self.META.get('CONTENT_LENGTH') or 0) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE): raise RequestDataTooBig('Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.') try: diff --git a/docs/releases/1.10.1.txt b/docs/releases/1.10.1.txt index 58619492a7f..d5bfcac2bdc 100644 --- a/docs/releases/1.10.1.txt +++ b/docs/releases/1.10.1.txt @@ -23,3 +23,6 @@ Bugfixes * Fixed a regression in the number of queries when using ``RadioSelect`` with a ``ModelChoiceField`` form field (:ticket:`27001`). + +* Fixed a crash if ``request.META['CONTENT_LENGTH']`` is an empty string + (:ticket:`27005`). diff --git a/tests/requests/test_data_upload_settings.py b/tests/requests/test_data_upload_settings.py index 8855e13336e..f60f1850ea2 100644 --- a/tests/requests/test_data_upload_settings.py +++ b/tests/requests/test_data_upload_settings.py @@ -104,6 +104,10 @@ class DataUploadMaxMemorySizeGetTests(SimpleTestCase): with self.settings(DATA_UPLOAD_MAX_MEMORY_SIZE=None): self.request.body + def test_empty_content_length(self): + self.request.environ['CONTENT_LENGTH'] = '' + self.request.body + class DataUploadMaxNumberOfFieldsGet(SimpleTestCase):