Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#27005 closed Bug (fixed)

request.body raises an exception if 'CONTENT_LENGTH' = ''

Reported by: Daniel Owned by: Tim Graham
Component: HTTP handling Version: 1.10
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

invalid literal for int() with base 10:

/site-packages/django/http/request.py in body

line 267

# request.META['CONTENT_LENGTH'] = ''

int(self.META.get('CONTENT_LENGTH', 0)) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE): 

Change History (13)

comment:1 by Baptiste Mispelon, 8 years ago

Hi,

Thanks for reporting this issue to us.
Could you provide some information on how you managed to trigger this error? A full traceback would also be helpful.

Thanks.

comment:2 by Daniel, 8 years ago

Environment:


Request Method: GET
Request URL: http://localhost:8000/myapp/

Django Version: 1.10
Python Version: 2.7.10
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "./python2.7/site-packages/django/core/handlers/exception.py" in inner
  39.             response = get_response(request)

File "./python2.7/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "./python2.7/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/testproject/myapp/views.py" in test_view
  7. 	assert False, request.body

File "./python2.7/site-packages/django/http/request.py" in body
  267.                     int(self.META.get('CONTENT_LENGTH', 0)) > settings.DATA_UPLOAD_MAX_MEMORY_SIZE):

Exception Type: ValueError at /myapp/
Exception Value: invalid literal for int() with base 10: ''

comment:4 by Baptiste Mispelon, 8 years ago

Could you also show us what testproject.myapp.views.test_view looks like?

Thanks.

comment:5 by Daniel, 8 years ago

from django.shortcuts import render

# Create your views here.


def test_view(request):

	assert False, request.body


comment:6 by Daniel, 8 years ago

# testproject/testproject/urls.py

"""testproject URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.10/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^myapp/', include('myapp.urls')),
    url(r'^admin/', admin.site.urls),
]

# testproject/myapp/urls.py

from django.conf.urls import url

from . import views

urlpatterns = [
        url(r'^$', views.test_view),
]

# testproject/myapp/views.py

from django.shortcuts import render

# Create your views here.


def test_view(request):

        assert False, request.body

comment:7 by Tim Graham, 8 years ago

Component: UncategorizedHTTP handling
Severity: NormalRelease blocker
Summary: request.body raises an exceptionrequest.body raises an exception if 'CONTENT_LENGTH' = ''
Triage Stage: UnreviewedAccepted

comment:8 by Baptiste Mispelon, 8 years ago

If it helps, here's a small testcase that reproduces the issue (it works on 1.9 but fails on 1.10):

from django.test import TestCase, RequestFactory

class ReproTestCase(TestCase):
    def test_repro(self):
        request = RequestFactory().get('/', CONTENT_LENGTH='')
        self.assertEqual(request.META['CONTENT_LENGTH'], '')
        self.assertFalse(request.body)

comment:9 by Tim Graham, 8 years ago

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:10 by Tim Graham, 8 years ago

Has patch: set

comment:11 by Baptiste Mispelon, 8 years ago

Triage Stage: AcceptedReady for checkin

Looks good to me, thanks.

comment:12 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 5c63b3e5:

Fixed #27005 -- Fixed crash if request.META[CONTENT_LENGTH']=.

comment:13 by Tim Graham <timograham@…>, 8 years ago

In dcebeea:

[1.10.x] Fixed #27005 -- Fixed crash if request.META[CONTENT_LENGTH']=.

Backport of 5c63b3e5a797102d915e1683971517f747a28013 from master

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