chiark / gitweb /
fix handling unreadable images in update.extract_apk_icons
[fdroidserver.git] / fdroidserver / update.py
index 4611b12761cdee5c5aebe69b11ca069dbbac412f..3015e337ca6325813337e1a8c6bb6dd66a7f4178 100644 (file)
@@ -1355,10 +1355,13 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
         apkzip = zipfile.ZipFile(apkfile, 'r')
 
         manifest = apkzip.getinfo('AndroidManifest.xml')
-        if manifest.date_time[1] == 0:  # month can't be zero
-            logging.debug(_('AndroidManifest.xml has no date'))
-        else:
-            common.check_system_clock(datetime(*manifest.date_time), apkfilename)
+        # 1980-0-0 means zeroed out, any other invalid date should trigger a warning
+        if (1980, 0, 0) != manifest.date_time[0:3]:
+            try:
+                common.check_system_clock(datetime(*manifest.date_time), apkfilename)
+            except ValueError as e:
+                logging.warning(_("{apkfilename}'s AndroidManifest.xml has a bad date: ")
+                                .format(apkfilename=apkfile) + str(e))
 
         # extract icons from APK zip file
         iconfilename = "%s.%s.png" % (apk['packageName'], apk['versionCode'])
@@ -1472,6 +1475,7 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
         icon_path = os.path.join(get_icon_dir(repo_dir, '0'), icon_filename)
         with open(icon_path, 'wb') as f:
             f.write(get_icon_bytes(apkzip, icon_src))
+        im = None
         try:
             im = Image.open(icon_path)
             dpi = px_to_dpi(im.size[0])
@@ -1487,6 +1491,9 @@ def extract_apk_icons(icon_filename, apk, apkzip, repo_dir):
         except Exception as e:
             logging.warning(_("Failed reading {path}: {error}")
                             .format(path=icon_path, error=e))
+        finally:
+            if im:
+                im.close()
 
     if apk['icons']:
         apk['icon'] = icon_filename