Fix crash when passing a very long cmdline argument (#11404)

Fixes #11394
This commit is contained in:
Bruno Oliveira
2023-09-07 12:49:25 -03:00
committed by GitHub
parent 333e4eba6b
commit 28ccf476b9
5 changed files with 77 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import atexit
import contextlib
import errno
import fnmatch
import importlib.util
import itertools
@@ -773,3 +774,13 @@ def bestrelpath(directory: Path, dest: Path) -> str:
# Forward from base to dest.
*reldest.parts,
)
def safe_exists(p: Path) -> bool:
"""Like Path.exists(), but account for input arguments that might be too long (#11394)."""
try:
return p.exists()
except OSError as e:
if e.errno == errno.ENAMETOOLONG:
return False
raise