-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Are there currently any enforced limits on the version string in metadata? I looked through the code, but couldn't find anything.
With no limit we can get denial of service attacks, only with Python 3.11 this is mitigated to some extend. See https://docs.python.org/3/library/stdtypes.html#int-max-str-digits, which in practice would apply a limit of 4300 digits per number element of a version.
My initial motivation was database side sorting in devpi. It is possible to construct comparable version strings, but they require the order of magnitude for numbers (see https://stackoverflow.com/a/30752452/3748142) and without limits this isn't possible. Also see the currently inefficient ordering in warehouse:
warehouse/warehouse/forklift/legacy.py
Lines 1176 to 1190 in 6d4b6a3
# TODO: We need a better solution to this than to just do it inline inside | |
# this method. Ideally the version field would just be sortable, but | |
# at least this should be some sort of hook or trigger. | |
releases = ( | |
request.db.query(Release) | |
.filter(Release.project == project) | |
.options( | |
orm.load_only(Release.project_id, Release.version, Release._pypi_ordering) | |
) | |
.all() | |
) | |
for i, r in enumerate( | |
sorted(releases, key=lambda x: packaging_legacy.version.parse(x.version)) | |
): | |
r._pypi_ordering = i |