update: Handle APKs without a version code in their manifest

This commit is contained in:
Tobias Mueller 2025-08-26 10:10:51 +00:00 committed by Hans-Christoph Steiner
parent d4ad523dd2
commit 2eb3986ecf
2 changed files with 15 additions and 2 deletions

View file

@ -35,6 +35,10 @@ class VCSException(FDroidException):
pass pass
class NoVersionCodeException(FDroidException):
pass
class NoSubmodulesException(VCSException): class NoSubmodulesException(VCSException):
pass pass

View file

@ -56,7 +56,7 @@ import fdroidserver.index
from . import _, common, metadata from . import _, common, metadata
from .common import DEFAULT_LOCALE from .common import DEFAULT_LOCALE
from .exception import BuildException, FDroidException, VerificationException from .exception import BuildException, FDroidException, NoVersionCodeException, VerificationException
if hasattr(Image, 'DecompressionBombWarning'): if hasattr(Image, 'DecompressionBombWarning'):
warnings.simplefilter('error', Image.DecompressionBombWarning) warnings.simplefilter('error', Image.DecompressionBombWarning)
@ -1801,6 +1801,7 @@ def scan_apk_androguard(apk, apkfile):
xml = apkobject.get_android_manifest_xml() xml = apkobject.get_android_manifest_xml()
androidmanifest_xml = apkobject.xml['AndroidManifest.xml'] androidmanifest_xml = apkobject.xml['AndroidManifest.xml']
if len(xml.nsmap) > 0: if len(xml.nsmap) > 0:
# one of them surely will be the Android one, or its corrupt # one of them surely will be the Android one, or its corrupt
xmlns = common.XMLNS_ANDROID xmlns = common.XMLNS_ANDROID
@ -1810,8 +1811,12 @@ def scan_apk_androguard(apk, apkfile):
xmlns = '{}' xmlns = '{}'
vcstr = androidmanifest_xml.get(xmlns + 'versionCode') vcstr = androidmanifest_xml.get(xmlns + 'versionCode')
logging.debug("Version Code: %r (%s)" % (vcstr, apkfile))
if vcstr.startswith('0x'): if not vcstr:
raise NoVersionCodeException(_("APK file {path} does not have a version code "
"in its manifest").format(path=apkfile))
elif vcstr.startswith('0x'):
apk['versionCode'] = int(vcstr, 16) apk['versionCode'] = int(vcstr, 16)
else: else:
apk['versionCode'] = int(vcstr) apk['versionCode'] = int(vcstr)
@ -1959,6 +1964,10 @@ def process_apk(apkcache, apkfilename, repodir, knownapks, use_date_from_apk=Fal
logging.warning(_("Skipping '{apkfilename}' with invalid signature!") logging.warning(_("Skipping '{apkfilename}' with invalid signature!")
.format(apkfilename=apkfilename)) .format(apkfilename=apkfilename))
return True, None, False return True, None, False
except NoVersionCodeException:
logging.warning(_("Skipping '{apkfilename}' without versionCode!")
.format(apkfilename=apkfilename))
return True, None, False
if apps: if apps:
if apk['packageName'] in apps: if apk['packageName'] in apps: