From 1f706283cedec66055d09b11bd74702861f18a5f Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Tue, 27 Mar 2018 14:17:08 +0200 Subject: [PATCH 1/2] Fix crash when icon_name is None Fixes the following crash: ``` $ fdroid update --create-metadata --rename-apks WARNING: Using Java's jarsigner, not recommended for verifying APKs! Use apksigner CRITICAL: Unknown exception found! Traceback (most recent call last): File "/home/jonas/miniconda3/bin/fdroid", line 164, in main() File "/home/jonas/miniconda3/bin/fdroid", line 138, in main mod.main() File "/home/jonas/miniconda/lib/python3.6/site-packages/fdroidserver/update.py", line 1927, in main apks, cachechanged = process_apks(apkcache, repodirs[0], knownapks, options.use_date_from_apk) File "/home/jonas/miniconda/lib/python3.6/site-packages/fdroidserver/update.py", line 1454, in process_apks use_date_from_apk, ada, True) File "/home/jonas/miniconda/lib/python3.6/site-packages/fdroidserver/update.py", line 1327, in process_apk apk = scan_apk(apkfile) File "/home/jonas/miniconda/lib/python3.6/site-packages/fdroidserver/update.py", line 1056, in scan_apk scan_apk_aapt(apk, apk_file) File "/home/jonas/miniconda/lib/python3.6/site-packages/fdroidserver/update.py", line 1184, in scan_apk_aapt apk['icons_src'] = _get_apk_icons_src(apkfile, icon_name) File "/home/jonas/miniconda/lib/python3.6/site-packages/fdroidserver/update.py", line 1089, in _get_apk_icons_src density_re = re.compile('^res/(.*)/' + icon_name + '\.(png|xml)$') TypeError: must be str, not NoneType ``` --- fdroidserver/update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 9c6c21f3..83f069fa 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -1086,7 +1086,7 @@ def _get_apk_icons_src(apkfile, icon_name): """ icons_src = dict() - density_re = re.compile('^res/(.*)/' + icon_name + '\.(png|xml)$') + density_re = re.compile('^res/(.*)/{}\.(png|xml)$'.format(icon_name)) with zipfile.ZipFile(apkfile) as zf: for filename in zf.namelist(): m = density_re.match(filename) From 9e4459d7d1497bcc3ad342d428ce6a49686668c0 Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Tue, 27 Mar 2018 18:39:59 +0200 Subject: [PATCH 2/2] Add test for when apk icon src could not be found An APK (Netflix) was found to have the following icon filename: \u2003\u2009\n.xml This breaks the aapt dump parsing because it iterates line by line and this filename goes across two lines. Consequently, icon_src will be None (default value) when it is passed to the icons parser. --- tests/update.TestCase | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/update.TestCase b/tests/update.TestCase index 03391c18..9c60adfd 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -647,6 +647,16 @@ class UpdateTest(unittest.TestCase): with self.assertRaises(fdroidserver.exception.FDroidException): fdroidserver.update.has_known_vulnerability('janus.apk') + def test_get_apk_icon_when_src_is_none(self): + config = dict() + fdroidserver.common.fill_config_defaults(config) + fdroidserver.common.config = config + fdroidserver.update.config = config + + # pylint: disable=protected-access + icons_src = fdroidserver.update._get_apk_icons_src('urzip-release.apk', None) + assert icons_src == {} + if __name__ == "__main__": parser = optparse.OptionParser()