From 6918df4f62a50d4a0fa06bbb8ed95e323b8599da Mon Sep 17 00:00:00 2001 From: "Manuel Amador (Rudd-O)" Date: Sun, 21 Aug 2022 01:31:24 +0000 Subject: [PATCH] Fix incomplete read from the remote side. --- connection_plugins/qubes.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/connection_plugins/qubes.py b/connection_plugins/qubes.py index 66531fa..70bb8b7 100644 --- a/connection_plugins/qubes.py +++ b/connection_plugins/qubes.py @@ -138,16 +138,20 @@ def put(out_path): chunksize = int(sys.stdin.readline(16)) if chunksize == 0: break - chunk = sys.stdin.read(chunksize) - assert len(chunk) == chunksize, ("Mismatch in chunk length", len(chunk), chunksize) - try: - f.write(chunk) - sys.stdout.write(b'Y\n') - except (IOError, OSError) as e: - sys.stdout.write(b'N\n') - encode_exception(e, sys.stdout) - f.close() - return + while True: + chunk = sys.stdin.read(chunksize) + if chunk == b"": + assert chunksize == 0, "Never could finish reading the last %s bytes" % chunksize + break + try: + f.write(chunk) + except (IOError, OSError) as e: + sys.stdout.write(b'N\n') + encode_exception(e, sys.stdout) + f.close() + return + chunksize = chunksize - len(chunk) + sys.stdout.write(b'Y\n') try: f.flush() except (IOError, OSError) as e: