Skip to content

Commit

Permalink
io: fix integer overflow in take (#6080)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored Oct 15, 2023
1 parent a08ad92 commit 654a3d5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tokio/src/io/util/take.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::io::{AsyncBufRead, AsyncRead, ReadBuf};

use pin_project_lite::pin_project;
use std::convert::TryFrom;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::{cmp, io};
Expand Down Expand Up @@ -85,7 +86,7 @@ impl<R: AsyncRead> AsyncRead for Take<R> {
}

let me = self.project();
let mut b = buf.take(*me.limit_ as usize);
let mut b = buf.take(usize::try_from(*me.limit_).unwrap_or(usize::MAX));

let buf_ptr = b.filled().as_ptr();
ready!(me.inner.poll_read(cx, &mut b))?;
Expand Down

0 comments on commit 654a3d5

Please sign in to comment.