Skip to content

A Series of Simple DOS Vulnerabilities #134873

Closed as duplicate
Closed as duplicate

Description

@kexinoh

Bug report

Update

Now, based on the specific location where the problem code appears, it has been re-split into five issues.

Bug description:

We have identified a series of simple quadratic complexity vulnerabilities. After confirmation by CPython's security team, since these DOS vulnerabilities pose a low threat and are relatively tedious to exploit, we can directly initiate requests in issues to seek assistance from the community for fixes.
Below are the specific locations of the different complexity issues we discovered.

1.

def expandvars(path):

2.
def _parseparam(s):

3.
while methodname[:1] == '<':

4.
def get_phrase(value):

5.
while value and (value[0]=='\\' or value[0] not in PHRASE_ENDS):

6.
value = value[1:]

7.
value = value[1:]

8.
value = value[1:]

9.
value = value[1:]

10.
value = value[1:]

11.
value = value[1:]

12.
value = value[1:]

13.
value = value[1:]

14.
value = value[1:]

15.
value = value[1:]

16.
to_encode = to_encode[1:]

17.
def expandvars(str, vars):

18.
def expandvars(path):

19.
while True:

20.
while line and line[-1] in " \t":

21.
while platform and platform[-1] == '-':

Current repair status:

03/19 has been fixed. @johnzhou721
1 has been fixed. @Wulian233
2/4/5/6/7/8/9/10/11/12/13/14/15/16 has been fixed. @picnixz
1/18 has been fixed. @serhiy-storchaka

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Credits

Finder is kexinoh (Xiangfan Wu) from QI-ANXIN Technology Research Institute.

Linked PRs

Activity

  1. sethmlarson commented on May 29, 2025

    @sethmlarson
    Contributor

    @ZeroIntensity Indeed, some of these have been reported to PSRT and I recommended a public issue.

  2. Wulian233 commented on May 30, 2025

    @Wulian233
    Contributor

    I fixed posixpath in #134927

  3. kexinoh commented on May 30, 2025

    @kexinoh
    Author

    I fixed posixpath in #134927

    Among them, both 17 and 18 belong to path replacement issues. I think you can fix them together, which will accelerate the repair speed. It should be additionally noted that other problems such as the infinite loop vulnerability caused by 17 need to be handled.

  4. johnzhou721 commented on May 30, 2025

    @johnzhou721
  5. picnixz commented on May 30, 2025

    @picnixz
  6. added
    stdlibStandard Library Python modules in the Lib/ directory
    on May 30, 2025
  7. johnzhou721 commented on May 30, 2025

    @johnzhou721
  8. picnixz commented on May 30, 2025

    @picnixz
  9. serhiy-storchaka commented on May 30, 2025

    @serhiy-storchaka
    Member

    As for expandvars(), there is a more efficient way. Also, I suspect there is other quadratic complexity vulnerability here. I am working on this.

  10. kexinoh commented on May 30, 2025

    @kexinoh
    Author

    As for , there is a more efficient way. Also, I suspect there is other quadratic complexity vulnerability here. I am working on this.expandvars()

    Yes, there are still some vulnerabilities.
    update: I have added two more.

  11. added a commit that references this issue on May 30, 2025
  12. self-assigned this
    on May 30, 2025
  13. added a commit that references this issue on May 31, 2025
  14. Wulian233 commented on May 31, 2025

    @Wulian233
    Contributor

    I may have found a new one:

    paths.extend(arg._raw_paths)

    import pathlib
    import time
    
    def create_deep_path(n):
        p = pathlib.PurePath("a")
        for _ in range(n):
            p = pathlib.PurePath(p, p) # Each iteration doubles the number of path segments
        return p
    start = time.time()
    # 2^20 ≈ 1,000,000
    deep_path = create_deep_path(20)
    str(deep_path)  # Path resolution is triggered, which consumes a large amount of resources
    end = time.time()
    print(f"Time taken: {end - start:.2f} seconds")

    Possible fix, replace with paths.append(str(arg))

    Now: Time taken: 0.51 seconds
    Fix: Time taken: 0.24 seconds

    @barneygale Can you be confirm this?

    Edit: 3.14 3.15 only #130748

  15. picnixz commented on May 31, 2025

    @picnixz
    Member

    _raw_paths contains unjoined parts, so we still them in full:

    # The `_raw_paths` slot stores unjoined string paths. This is set in
    # the `__init__()` method.
    '_raw_paths',

    Note that str(...) actually joins the string paths, so the behavior is not the same.

  16. johnzhou721 commented on Jun 22, 2025

    @johnzhou721
    Contributor

    FYI: 19 is potentially non-exploitable if we can limit the maximum of indentwidth when loading the config (What's the difference between self.indentwidth and self.tabwidth in the editor anyways?)

  17. serhiy-storchaka commented on Jun 28, 2025

    @serhiy-storchaka
    Member

    Please open separate issue for each problem. os.path, IDLE, email -- they all are very different and need different solutions.

  18. kexinoh commented on Jun 28, 2025

    @kexinoh
    Author
  19. kexinoh commented on Jun 28, 2025

    @kexinoh
    Author

    I have added fout new issues.
    #136061
    #136063
    #136065
    #136066

  20. StanFromIreland commented on Jun 28, 2025

    @StanFromIreland
    Member

    Is there any left here or can this be closed now?

  21. picnixz commented on Jun 28, 2025

    @picnixz
  22. picnixz commented on Jun 28, 2025

    @picnixz
    Member

    Actually no, please open issues for platform and tools (or maybe it's under the os.path issue) as well.

  23. picnixz commented on Jun 28, 2025

    @picnixz
    Member

    The platform issue is actually straightforward and I can take care of it now.

  24. kexinoh commented on Jun 28, 2025

    @kexinoh
    Author

    I updated it at the top of this issue to indicate that it has been split, which will help readers understand it quickly.

    Ok. I put them in the PATH. Now it seems that it can be turned off.

  25. picnixz commented on Jun 28, 2025

    @picnixz
    Member

    No I meant, the platform one is separate from the path issues. But the checkextensions one is a path-one as it's expandvars-related

  26. kexinoh commented on Jun 28, 2025

    @kexinoh
    Author
  27. picnixz commented on Jun 28, 2025

    @picnixz
    Member

    Thanks. We'll close this issue in particular and focus on the dedicated ones instead. Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.10 (EOL)end of life3.11only security fixes3.12only security fixes3.13only security fixes3.14bugs and security fixes3.9 (EOL)end of lifependingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-emailtopic-pathlibtype-securityA security issue

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions