Skip to content

Commit e50f0d0

Browse files
oech3cakebaker
authored andcommitted
pipes.rs: add debug_assert! for RAM usage
1 parent 9327ffb commit e50f0d0

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/uucore/src/lib/features/pipes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ where
117117
// we can recover by copying the data that we have from the
118118
// intermediate pipe to stdout using normal read/write. Then
119119
// we tell the caller to fall back.
120-
let mut drain = Vec::with_capacity(n); // bounded by pipe size
120+
debug_assert!(n <= MAX_ROOTLESS_PIPE_SIZE, "unexpected RAM usage");
121+
let mut drain = Vec::with_capacity(n);
121122
pipe_rd.take(n as u64).read_to_end(&mut drain)?;
122123
dest.write_all(&drain)?;
123124
return Ok(true);
@@ -184,7 +185,8 @@ pub fn send_n_bytes(
184185
break false;
185186
}
186187
} else {
187-
let mut drain = Vec::with_capacity(s); // bounded by pipe size
188+
debug_assert!(s <= MAX_ROOTLESS_PIPE_SIZE, "unexpected RAM usage");
189+
let mut drain = Vec::with_capacity(s);
188190
broker_r.take(s as u64).read_to_end(&mut drain)?;
189191
target.write_all(&drain)?;
190192
break true;

0 commit comments

Comments
 (0)