Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIX: Improve procfiles regexp speed #2457

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

AlekseyLobanov
Copy link
Contributor

@AlekseyLobanov AlekseyLobanov commented Oct 10, 2024

Improves speed from exponential on bad strings like "S_IFREG' + ' ' * 150"
to polynomial.

Summary

  • OS: AIX
  • Bug fix: yes
  • Type: performance
  • Fixes: { comma-separated list of issues fixed by this PR, if any }

Description

Current RegExp is vulnerable to ReDoS.

POC for regexps is below:

import re
import time

COUNT = 100

for re_text, name in [
    (r"(\d+): S_IFREG.*\s*.*name:(.*)\n", "current"),
    (r"(\d+): S_IFREG.*name:(.*)\n", "fixed"),
]:
    begin_at = time.time()
    for _ in range(COUNT):
        re.findall(re_text, "S_IFREG' + ' ' * 150")
    print(f"Total for {name:8} is {time.time() - begin_at:.6f}")

My output is below

Total for current  is 0.000119
Total for fixed    is 0.000031

Improves speed from exponential on bad strings like
`"S_IFREG' + ' ' * 150"`
to polynomial.
@giampaolo
Copy link
Owner

Can you also update HISTORY.rst and CREDITS?

@AlekseyLobanov
Copy link
Contributor Author

Done

@giampaolo giampaolo merged commit b19d5bd into giampaolo:master Oct 15, 2024
14 of 16 checks passed
@giampaolo
Copy link
Owner

Merged. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants