From 4c91b28cf37dab8cbb3cbdcfba08960d34283f8c Mon Sep 17 00:00:00 2001 From: dawn <90008@klbr.net> Date: Fri, 2 Oct 2026 23:31:09 +0300 Subject: [PATCH] remote: send rem.write's text on stdin, so a file past the host's argument limit writes Signed-off-by: dawn <90008@klbr.net> --- priv/python/albedo_plugins/remote.py | 15 +++++++-------- test/harness/remote_plugin_test.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/priv/python/albedo_plugins/remote.py b/priv/python/albedo_plugins/remote.py index 5ad73a790..d56073d16 100644 --- a/priv/python/albedo_plugins/remote.py +++ b/priv/python/albedo_plugins/remote.py @@ -856,9 +856,11 @@ class RemoteConnection: ) return "attached " + attach_image(data) - async def _ssh(self, script: str, timeout: float) -> bytes: + async def _ssh( + self, script: str, timeout: float, stdin: bytes | None = None + ) -> bytes: code, stdout, stderr = await ssh_run( - self.host, in_login_shell(script), timeout=timeout + self.host, in_login_shell(script), timeout=timeout, stdin=stdin ) if code != 0: raise RemoteError(f"SSH failed ({code}): {stderr.strip()}") @@ -867,13 +869,10 @@ class RemoteConnection: async def write( self, path: str, content: str, *, timeout: float = COMMAND_TIMEOUT ) -> None: - """Replace a remote file; bytes travel base64, never as shell text.""" + """Replace a remote file. The text travels on stdin, never in the + command line, which a host caps (128 KiB per argument on Linux).""" remote = _remote_path(self, path) - encoded = base64.b64encode(content.encode()).decode() - await self._ssh( - f"printf %s {shlex.quote(encoded)} | base64 -d > {shlex.quote(remote)}", - timeout, - ) + await self._ssh(f"cat > {shlex.quote(remote)}", timeout, content.encode()) # --- degraded mode --- diff --git a/test/harness/remote_plugin_test.py b/test/harness/remote_plugin_test.py index bd85e3ad8..2ac619e44 100644 --- a/test/harness/remote_plugin_test.py +++ b/test/harness/remote_plugin_test.py @@ -295,6 +295,16 @@ class RemotePluginTest(unittest.IsolatedAsyncioTestCase): ending = await job.stop # awaiting an uncalled method runs it self.assertTrue(ending.gone) + async def test_a_file_larger_than_a_command_line_writes_and_reads_back(self): + rem = await self.connect() + self.addCleanup(rem.close) + # Past macOS's whole ARG_MAX and Linux's 128 KiB per argument, so the + # text must travel on stdin rather than in the remote command. + content = "".join(f"line {index} ΓΌ\n" for index in range(150_000)) + await rem.write("big.lock", content) + self.assertEqual(Path(self.workspace, "big.lock").read_text(), content) + self.assertEqual(await rem.read("big.lock"), content) + async def test_session_tools_relay_to_this_daemon(self): rem = await self.connect() self.addCleanup(rem.close) -- knotmirror 0.0.1