Prevent video plugin from processing svg [#934]
authorAndrew Browning <ayleph@thisshitistemp.com>
Wed, 25 Oct 2017 06:33:49 +0000 (02:33 -0400)
committerAndrew Browning <ayleph@thisshitistemp.com>
Wed, 4 Apr 2018 21:11:15 +0000 (17:11 -0400)
Prior to the gstreamer-1.0 upgrade, the video processing engine included
a check for excluded extensions which gstreamer might accept despite us
not wanting to process them. In commit 91f5f5e, the check against
EXCLUDED_EXT was removed. Since then, the video plugin has accepted and
attempted to process svg files.

This commit adds the check against EXCLUDED_EXTS into the sniff_handler
function so that we can bail out on certain file extensions before the
plugins tries to sniff the file type. The previous implementation
excluded nef files, which appears to be a Nikon camera image. I've
copied that forward to this code. I've also added a log message to
indicate that we're purposefully refusing to process the file.

mediagoblin/media_types/video/processing.py

index ca3087a2c399564cf2f2f18557dee6d76c9fde83..3168c0548f3cced6ef23d836c9794d9fc43cdf02 100644 (file)
@@ -79,7 +79,17 @@ def sniffer(media_file):
     return MEDIA_TYPE
 
 
+EXCLUDED_EXTS = ["nef", "svg"]
+
 def sniff_handler(media_file, filename):
+    name, ext = os.path.splitext(filename)
+    clean_ext = ext.lower()[1:]
+
+    if clean_ext in EXCLUDED_EXTS:
+        # We don't handle this filetype, though gstreamer might think we can
+        _log.info('Refused to process {0} due to excluded extension'.format(filename))
+        return None
+
     try:
         return sniffer(media_file)
     except: