mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
[1.7.x] Prevented views.static.serve() from using large memory on large files.
This is a security fix. Disclosure following shortly.
This commit is contained in:
1
tests/view_tests/media/long-line.txt
Normal file
1
tests/view_tests/media/long-line.txt
Normal file
File diff suppressed because one or more lines are too long
@@ -8,7 +8,7 @@ from django.conf.urls.static import static
|
||||
from django.http import HttpResponseNotModified
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
from django.utils.http import http_date
|
||||
from django.views.static import was_modified_since
|
||||
from django.views.static import was_modified_since, STREAM_CHUNK_SIZE
|
||||
|
||||
from .. import urls
|
||||
from ..urls import media_dir
|
||||
@@ -33,6 +33,14 @@ class StaticTests(SimpleTestCase):
|
||||
self.assertEqual(len(response_content), int(response['Content-Length']))
|
||||
self.assertEqual(mimetypes.guess_type(file_path)[1], response.get('Content-Encoding', None))
|
||||
|
||||
def test_chunked(self):
|
||||
"The static view should stream files in chunks to avoid large memory usage"
|
||||
response = self.client.get('/%s/%s' % (self.prefix, 'long-line.txt'))
|
||||
first_chunk = next(response.streaming_content)
|
||||
self.assertEqual(len(first_chunk), STREAM_CHUNK_SIZE)
|
||||
second_chunk = next(response.streaming_content)
|
||||
self.assertEqual(len(second_chunk), 1451)
|
||||
|
||||
def test_unknown_mime_type(self):
|
||||
response = self.client.get('/%s/file.unknown' % self.prefix)
|
||||
self.assertEqual('application/octet-stream', response['Content-Type'])
|
||||
|
||||
Reference in New Issue
Block a user