Skip to content

os.path.realpath raises a ValueError when path contains a null byte #117596

Open
@stefanhoelzl

Description

@stefanhoelzl

Bug report

Bug description:

import os
os.path.realpath("\x00")  # raises unexpected ValueError

The ValueError is initially raised by os.lstat.

This behavior is inconsistent with other path operations catching the ValueError raised by os.lstat:
os.path.lexsists: https://github.com/python/cpython/blob/main/Lib/genericpath.py#L30
os.path.exists: https://github.com/python/cpython/blob/main/Lib/genericpath.py#L20
os.path.islink: https://github.com/python/cpython/blob/main/Lib/genericpath.py#L64
os.path.ismount: https://github.com/python/cpython/blob/main/Lib/posixpath.py#L197
os.path.ismount: https://github.com/python/cpython/blob/main/Lib/posixpath.py#L213

CPython versions tested on:

3.10, CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions