Skip to content

Commit

Permalink
io: fix unsoundness in read_to_end (#3428)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored and carllerche committed Jan 15, 2021
1 parent ecc32d1 commit 0a7117f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
on:
push:
branches: ["master"]
branches: ["master", "tokio-*.x"]
pull_request:
branches: ["master"]
branches: ["master", "tokio-*.x"]

name: CI

Expand Down
5 changes: 2 additions & 3 deletions tokio/src/io/util/read_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,13 @@ fn poll_read_to_end<R: AsyncRead + ?Sized>(

let mut unused_capacity = ReadBuf::uninit(get_unused_capacity(buf));

let ptr = unused_capacity.filled().as_ptr();
ready!(read.poll_read(cx, &mut unused_capacity))?;
assert_eq!(ptr, unused_capacity.filled().as_ptr());

let n = unused_capacity.filled().len();
let new_len = buf.len() + n;

// This should no longer even be possible in safe Rust. An implementor
// would need to have unsafely *replaced* the buffer inside `ReadBuf`,
// which... yolo?
assert!(new_len <= buf.capacity());
unsafe {
buf.set_len(new_len);
Expand Down

0 comments on commit 0a7117f

Please sign in to comment.