[extensions-web] extensions: don't fail in Extension.save() if old zip is corrupted.



commit 9b4e4b93e47bed01daff0b5d0c0367008064bb67
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Thu Apr 4 19:22:49 2019 +0400

    extensions: don't fail in Extension.save() if old zip is corrupted.
    
    Saving Extension model trigger update of all extension versions as well as
    extension's zip archives. Corrupted archive can be cause of BadZipfile
    exception that we ignore. However zlib.error may be also thrown which also
    should be handled.
    
    Fixes: https://extensions.gnome.org/extension/1254/obmin/

 sweettooth/extensions/models.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index 0642e7e..88857d1 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -10,6 +10,7 @@ from django.urls import reverse
 
 import autoslug
 import re
+import zlib
 
 (STATUS_UNREVIEWED,
  STATUS_REJECTED,
@@ -131,7 +132,7 @@ class Extension(models.Model):
                 if version.source:
                     try:
                         version.replace_metadata_json()
-                    except BadZipfile:
+                    except (BadZipfile, zlib.error):
                         # Ignore bad zipfiles, we don't care
                         pass
 
@@ -254,7 +255,7 @@ def parse_zipfile_metadata(uploaded_file):
     """
     try:
         zipfile = ZipFile(uploaded_file, 'r')
-    except BadZipfile:
+    except (BadZipfile, zlib.error):
         raise InvalidExtensionData("Invalid zip file")
 
     if zipfile.testzip() is not None:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]