`os.path.realpath` raises a `ValueError` when path contains a null byte
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
- gh-117573
- gh-134189
- gh-134265
- gh-134266
- gh-142415
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the null-byte case with os.path.realpath, then inspect the os.lstat handling in Lib/genericpath.py and Lib/posixpath.py, especially the cited exists, lexists, islink, and ismount implementations. Done means realpath handles the ValueError consistently with those path operations; review the linked PRs before starting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 20/100