Verified Commit 5afc3e46 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fix #266: Ensure we do not store bad mimetypes

parent a00a6162
......@@ -43,9 +43,9 @@ def get_query(query_string, search_fields):
def guess_mimetype(f):
b = min(100000, f.size)
b = min(1000000, f.size)
t = magic.from_buffer(, mime=True)
if t == 'application/octet-stream':
if not t.startswith('audio/'):
# failure, we try guessing by extension
mt, _ = mimetypes.guess_type(f.path)
if mt:
......@@ -15,9 +15,13 @@ def test_guess_mimetype_try_using_extension(factories, mocker):
assert utils.guess_mimetype(f.audio_file) == 'audio/mpeg'
def test_guess_mimetype_try_using_extension_if_fail(factories, mocker):
@pytest.mark.parametrize('wrong', [
def test_guess_mimetype_try_using_extension_if_fail(wrong, factories, mocker):
'magic.from_buffer', return_value='application/octet-stream')
'magic.from_buffer', return_value=wrong)
f = factories['music.TrackFile'].build(
Ensure we do not store bad mimetypes (such as application/x-empty) (#266)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment