1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-05 15:00:11 +01:00

Merge branch 'NoahAndrews-master-patch-97157' into 'master'

Handle error when parsing WebView icon

Closes #903

See merge request fdroid/fdroidserver!1018
This commit is contained in:
Hans-Christoph Steiner 2021-10-01 15:01:21 +00:00
commit bd079c9311
3 changed files with 35 additions and 1 deletions

View File

@ -1543,8 +1543,8 @@ def scan_apk_androguard(apk, apkfile):
icon_id_str = apkobject.get_element("application", "icon")
if icon_id_str:
icon_id = int(icon_id_str.replace("@", "0x"), 16)
try:
icon_id = int(icon_id_str.replace("@", "0x"), 16)
resource_id = arsc.get_id(apk['packageName'], icon_id)
if resource_id:
icon_name = arsc.get_id(apk['packageName'], icon_id)[1]

Binary file not shown.

View File

@ -843,6 +843,40 @@ class UpdateTest(unittest.TestCase):
with self.assertRaises(fdroidserver.exception.BuildException):
fdroidserver.update.scan_apk(apkfile)
@unittest.skipUnless(
os.path.exists('tests/SystemWebView-repack.apk'), "file too big for sdist"
)
def test_scan_apk_bad_icon_id(self):
"""Some APKs can produce an exception when extracting the icon
This kind of parsing exception should be reported then ignored
so that working APKs can be included in the index. There are
so many weird things that make it into APKs, that does not
automatically disqualify them from inclusion. For example:
ValueError: invalid literal for int() with base 16: '<0x801FF, type 0x07>'
The test APK was made from:
https://gitlab.com/fdroid/fdroidserver/-/merge_requests/1018#note_690565333
It was then stripped down by doing:
* mkdir SystemWebView
* cd SystemWebView/
* unzip ../SystemWebView.apk
* rm -rf META-INF/ lib assets/icudtl.dat assets/stored-locales/
* jar cf ../SystemWebView-repack.apk *
"""
# reset the state, perhaps this should be in setUp()
config = dict()
fdroidserver.common.fill_config_defaults(config)
fdroidserver.common.config = config
fdroidserver.update.config = config
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
os.mkdir('repo')
apkfile = 'repo/SystemWebView-repack.apk'
shutil.copy(os.path.join(self.basedir, os.path.basename(apkfile)), apkfile)
fdroidserver.update.scan_apk(apkfile)
def test_process_apk(self):
def _build_yaml_representer(dumper, data):
'''Creates a YAML representation of a Build instance'''