rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.31k stars 609 forks source link

Infinite loop caused by invalid UTF-8 bytes #2784

Closed newca12 closed 8 months ago

newca12 commented 8 months ago

This is easyly reproducible on the master branch and also on the 0.3 branch

use futures::{io::BufReader, StreamExt};
use futures::AsyncBufReadExt;

#[tokio::main]
async fn main() {
    let bytes: [u8; 44] = [
        0x70, 0x69, 0x65, 0x72, 0x72, 0x65, 0x0a, 0x70, 0x61, 0x75, 0x6c, 0x0a, 0x76, 0x69, 0x6e,
        0x63, 0x65, 0x6e, 0x74, 0x0a, 0x61, 0x75, 0x72, 0xe9, 0x6c, 0x69, 0x65, 0x0a, 0x6f, 0x6c,
        0x69, 0x76, 0x69, 0x65, 0x72, 0x0a, 0x62, 0x65, 0x72, 0x6e, 0x61, 0x72, 0x64, 0x0a,
    ];
    let stream = BufReader::new(bytes.as_slice()).lines();
    let stream = stream.map(|_f| {
        //dbg!(_f);
        ()
    });
    stream.collect::<()>().await;
}