mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 05:34:49 +08:00
Check AF_UNIX path length (#7951)
This commit is contained in:
@@ -394,6 +394,7 @@ class Node:
|
||||
socket_path (string): the socket file to prepare.
|
||||
"""
|
||||
result = socket_path
|
||||
is_mac = sys.platform.startswith("darwin")
|
||||
if sys.platform == "win32":
|
||||
if socket_path is None:
|
||||
result = "tcp://{}:{}".format(self._localhost,
|
||||
@@ -407,6 +408,12 @@ class Node:
|
||||
raise RuntimeError(
|
||||
"Socket file {} exists!".format(socket_path))
|
||||
try_to_create_directory(os.path.dirname(socket_path))
|
||||
|
||||
# Check socket path length to make sure it's short enough
|
||||
maxlen = (104 if is_mac else 108) - 1 # sockaddr_un->sun_path
|
||||
if len(result.split("://", 1)[-1].encode("utf-8")) > maxlen:
|
||||
raise OSError("AF_UNIX path length cannot exceed "
|
||||
"{} bytes: {!r}".format(maxlen, result))
|
||||
return result
|
||||
|
||||
def start_reaper_process(self):
|
||||
|
||||
@@ -72,6 +72,12 @@ def test_tempdir_commandline():
|
||||
ignore_errors=True)
|
||||
|
||||
|
||||
def test_tempdir_long_path():
|
||||
temp_dir = os.path.join(ray.utils.get_user_temp_dir(), "z" * 108)
|
||||
with pytest.raises(OSError):
|
||||
ray.init(temp_dir=temp_dir) # path should be too long
|
||||
|
||||
|
||||
def test_raylet_socket_name(shutdown_only):
|
||||
ray.init(
|
||||
raylet_socket_name=os.path.join(ray.utils.get_user_temp_dir(),
|
||||
|
||||
Reference in New Issue
Block a user