Thanks to visit codestin.com
Credit goes to github.com

Skip to content

os.path.ismount() doesn't properly use byte-paths from an os.DirEntry #96192

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

Closed
calestyo opened this issue Aug 22, 2022 · 3 comments
Closed

os.path.ismount() doesn't properly use byte-paths from an os.DirEntry #96192

calestyo opened this issue Aug 22, 2022 · 3 comments
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@calestyo
Copy link
Contributor

calestyo commented Aug 22, 2022

Bug report

It seems that os.path.ismount() doesn't properly use a bytes-path from an os.DirEntry object (despite both claiming to support/be PathLike).

Take e.g. the following code, when called with a bytes path:

def scandirtree(path=b".", xdev=True):
    for p in os.scandir(path):
        yield p
        if p.is_dir(follow_symlinks=False)   and   ( not xdev  or  not os.path.ismount(p) ):
            yield from scandirtree(p, xdev)

That fails with:

Traceback (most recent call last):
  File "/home/calestyo/prj/generate-file-list/src/./generate-file-list", line 65, in <module>
    main()
  File "/home/calestyo/prj/generate-file-list/src/./generate-file-list", line 52, in main
    for p in scandirtree(ap, args.xdev):
  File "/home/calestyo/prj/generate-file-list/src/./generate-file-list", line 25, in scandirtree
    if p.is_dir(follow_symlinks=False)   and   ( not xdev  or  not os.path.ismount(p) ):
  File "/usr/lib/python3.10/posixpath.py", line 201, in ismount
    parent = join(path, '..')
  File "/usr/lib/python3.10/posixpath.py", line 90, in join
    genericpath._check_arg_types('join', a, *p)
  File "/usr/lib/python3.10/genericpath.py", line 155, in _check_arg_types
    raise TypeError("Can't mix strings and bytes in path components") from None
TypeError: Can't mix strings and bytes in path components

See also https://discuss.python.org/t/bug-in-os-path-ismount-or-perhaps-os-direntry/18406

Your environment

  • CPython versions tested on: 3.10.6
  • Operating system and architecture: Debian sid, x86_64

Cheers,
Chris.

Linked PRs

@calestyo calestyo added the type-bug An unexpected behavior, bug, or error label Aug 22, 2022
@eryksun eryksun added stdlib Python modules in the Lib dir 3.11 only security fixes 3.10 only security fixes 3.12 only security fixes easy labels Aug 23, 2022
@eryksun
Copy link
Contributor

eryksun commented Aug 23, 2022

posixpath.ismount() mistakenly checks isinstance(path, bytes) without first ensuring that the type is str or bytes via path = os.fspath(path).

@calestyo
Copy link
Contributor Author

Shall I provide a patch?

JelleZijlstra added a commit that referenced this issue Nov 14, 2022
Signed-off-by: Christoph Anton Mitterer <[email protected]>
Co-authored-by: Eryk Sun <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 14, 2022
…ythonGH-96194)

(cherry picked from commit 367f552)

Co-authored-by: Christoph Anton Mitterer <[email protected]>
Signed-off-by: Christoph Anton Mitterer <[email protected]>
Co-authored-by: Eryk Sun <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 14, 2022
…ythonGH-96194)

(cherry picked from commit 367f552)

Co-authored-by: Christoph Anton Mitterer <[email protected]>
Signed-off-by: Christoph Anton Mitterer <[email protected]>
Co-authored-by: Eryk Sun <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
@hauntsaninja
Copy link
Contributor

Thanks, looks like this has been fixed!

miss-islington added a commit that referenced this issue Nov 30, 2022
(cherry picked from commit 367f552)

Co-authored-by: Christoph Anton Mitterer <[email protected]>
Signed-off-by: Christoph Anton Mitterer <[email protected]>
Co-authored-by: Eryk Sun <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
JelleZijlstra added a commit that referenced this issue Jan 22, 2023
…H-96194) (#99456)

gh-96192: fix os.ismount() to use a path that is str or bytes (GH-96194)
(cherry picked from commit 367f552)

Signed-off-by: Christoph Anton Mitterer <[email protected]>
Co-authored-by: Christoph Anton Mitterer <[email protected]>
Co-authored-by: Eryk Sun <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes 3.11 only security fixes 3.12 only security fixes easy stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants