Skip to content

Commit b3f9e73

Browse files
authored
Rollup merge of rust-lang#119999 - onur-ozkan:remote-test-tools, r=Mark-Simulacrum
remote-test: use u64 to represent file size Currently, triggering a transfer of data exceeding the size of 4294967295 bytes results in a panic on the `remote-test-server` as `io::copy(&mut file, dst) failed with Connection reset by peer (os error 104)`. This issue happens because the size is transmitted as u32 to `remote-test-server`. First commit increases the supported file size. But I am not sure about its necessity — can we realistically encounter file sizes exceeding 4GB in builds, perhaps through some complicated configurations? ~The second commit adds a sanity check to avoid encountering the error `io::copy(&mut file, dst) failed with Connection reset by peer (os error 104)` on the `remote-test-server` side.~
2 parents e847889 + 1afd216 commit b3f9e73

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/tools/remote-test-client/src/main.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -300,18 +300,16 @@ fn run(support_lib_count: usize, exe: String, all_args: Vec<String>) {
300300

301301
// Ok now it's time to read all the output. We're receiving "frames"
302302
// representing stdout/stderr, so we decode all that here.
303-
let mut header = [0; 5];
303+
let mut header = [0; 9];
304304
let mut stderr_done = false;
305305
let mut stdout_done = false;
306306
let mut client = t!(client.into_inner());
307307
let mut stdout = io::stdout();
308308
let mut stderr = io::stderr();
309309
while !stdout_done || !stderr_done {
310310
t!(client.read_exact(&mut header));
311-
let amt = ((header[1] as u64) << 24)
312-
| ((header[2] as u64) << 16)
313-
| ((header[3] as u64) << 8)
314-
| ((header[4] as u64) << 0);
311+
let amt = u64::from_be_bytes(header[1..9].try_into().unwrap());
312+
315313
if header[0] == 0 {
316314
if amt == 0 {
317315
stdout_done = true;
@@ -349,7 +347,8 @@ fn send(path: &Path, dst: &mut dyn Write) {
349347
t!(dst.write_all(&[0]));
350348
let mut file = t!(File::open(&path));
351349
let amt = t!(file.metadata()).len();
352-
t!(dst.write_all(&[(amt >> 24) as u8, (amt >> 16) as u8, (amt >> 8) as u8, (amt >> 0) as u8,]));
350+
351+
t!(dst.write_all(&amt.to_be_bytes()));
353352
t!(io::copy(&mut file, dst));
354353
}
355354

src/tools/remote-test-server/src/main.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ fn recv<B: BufRead>(dir: &Path, io: &mut B) -> PathBuf {
347347
// the filesystem limits.
348348
let len = cmp::min(filename.len() - 1, 50);
349349
let dst = dir.join(t!(str::from_utf8(&filename[..len])));
350-
let amt = read_u32(io) as u64;
350+
let amt = read_u64(io);
351351
t!(io::copy(&mut io.take(amt), &mut t!(File::create(&dst))));
352352
set_permissions(&dst);
353353
dst
@@ -365,7 +365,7 @@ fn my_copy(src: &mut dyn Read, which: u8, dst: &Mutex<dyn Write>) {
365365
loop {
366366
let n = t!(src.read(&mut b));
367367
let mut dst = dst.lock().unwrap();
368-
t!(dst.write_all(&create_header(which, n as u32)));
368+
t!(dst.write_all(&create_header(which, n as u64)));
369369
if n > 0 {
370370
t!(dst.write_all(&b[..n]));
371371
} else {
@@ -377,21 +377,21 @@ fn my_copy(src: &mut dyn Read, which: u8, dst: &Mutex<dyn Write>) {
377377
fn batch_copy(buf: &[u8], which: u8, dst: &Mutex<dyn Write>) {
378378
let n = buf.len();
379379
let mut dst = dst.lock().unwrap();
380-
t!(dst.write_all(&create_header(which, n as u32)));
380+
t!(dst.write_all(&create_header(which, n as u64)));
381381
if n > 0 {
382382
t!(dst.write_all(buf));
383383
// Marking buf finished
384384
t!(dst.write_all(&[which, 0, 0, 0, 0,]));
385385
}
386386
}
387387

388-
const fn create_header(which: u8, n: u32) -> [u8; 5] {
388+
const fn create_header(which: u8, n: u64) -> [u8; 9] {
389389
let bytes = n.to_be_bytes();
390-
[which, bytes[0], bytes[1], bytes[2], bytes[3]]
390+
[which, bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7]]
391391
}
392392

393-
fn read_u32(r: &mut dyn Read) -> u32 {
394-
let mut len = [0; 4];
393+
fn read_u64(r: &mut dyn Read) -> u64 {
394+
let mut len = [0; 8];
395395
t!(r.read_exact(&mut len));
396-
u32::from_be_bytes(len)
396+
u64::from_be_bytes(len)
397397
}

0 commit comments

Comments
 (0)