You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Un-necessary loglinear complexity in platform._platform #136066
In practice, this one doesn't seem exploitable because that means that uname() must be VERY LARGE. And it's not like an adversary may change this at will. So I wouldn't consider it a security issue, just a possible improvement.
changed the title [-]Potential Quadratic Complexity DoS Risk in platform.py[/-][+]Platform: Performance Issue with Long Lines Due to Quadratic Complexity [/+]on Jun 28, 2025
changed the title [-]Platform: Performance Issue with Long Lines Due to Quadratic Complexity [/-][+]Un-necessary quadratic complexity in `platform._platform`[/+]on Jun 28, 2025
@serhiy-storchaka Historically, did we treat such cases as bugfixes, features or security fixes? I don't think it's a security issue, but it can be regarded as a small bug. Benchmarks however show no differences as platform.platform() calls are cached and since the function is private, it shouldn't be used elsewhere.
The asymptotic complexity is not quadratic, but $O(n\log{n})$. Each iteration of the first loop halves the number of repeated minuses, so there are at most $\log_2{n}$ iterations. The second loop is repeated at most once, since there is no more than one trailing minus left.
changed the title [-]Un-necessary quadratic complexity in `platform._platform`[/-][+]Un-necessary loglinear complexity in `platform._platform`[/+]on Jun 28, 2025
Activity
picnixz commentedon Jun 28, 2025
In practice, this one doesn't seem exploitable because that means that uname() must be VERY LARGE. And it's not like an adversary may change this at will. So I wouldn't consider it a security issue, just a possible improvement.
kexinoh commentedon Jun 28, 2025
I'll modify the expression
[-]Potential Quadratic Complexity DoS Risk in platform.py[/-][+]Platform: Performance Issue with Long Lines Due to Quadratic Complexity [/+][-]Platform: Performance Issue with Long Lines Due to Quadratic Complexity [/-][+]Un-necessary quadratic complexity in `platform._platform`[/+]picnixz commentedon Jun 28, 2025
@serhiy-storchaka Historically, did we treat such cases as bugfixes, features or security fixes? I don't think it's a security issue, but it can be regarded as a small bug. Benchmarks however show no differences as
platform.platform()calls are cached and since the function is private, it shouldn't be used elsewhere.serhiy-storchaka commentedon Jun 28, 2025
The asymptotic complexity is not quadratic, but$O(n\log{n})$ . Each iteration of the first loop halves the number of repeated minuses, so there are at most $\log_2{n}$ iterations. The second loop is repeated at most once, since there is no more than one trailing minus left.
[-]Un-necessary quadratic complexity in `platform._platform`[/-][+]Un-necessary loglinear complexity in `platform._platform`[/+]serhiy-storchaka commentedon Jun 28, 2025
I would treat this issue as cosmetic. The code can be reduced to few lines by using
reand string methods instead of manual loops.gh-136066: simplify `platform._platform()` (#136069)
pythongh-136066: simplify `platform._platform()` (python#136069)
pythongh-136066: simplify `platform._platform()` (python#136069)
pythongh-136066: simplify `platform._platform()` (python#136069)
pythongh-136066: simplify `platform._platform()` (python#136069)