Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Input Exceeds Length Limit Causes Read Limitation and Infinite Wait #614

Open
yingjun-wu opened this issue Jun 11, 2024 · 0 comments

Comments

@yingjun-wu
Copy link

let mut stream = BufReader::new(TcpStream::connect("cat")?);
stream.get_mut().write_all(b"Hello, world!\n")?;
let mut echo = String::new();
let mut b = BufReader::new(stream);
b.read_line(&mut echo)?;
println!("{}", echo);

Description:
I encountered an issue with the input handling in the system using the following test code. The problem occurs under the following scenarios:

  • When the input buffer length exceeds 8192 bytes, the read operation only retrieves 8192 bytes of data.
  • When the input length buffer exceeds 24576 bytes, the program enters an infinite wait with no output and does not exit.

Steps to Reproduce:

Use the provided test code.

  • Run the code with an input bufferlength of 16384 bytes.
  • Observe that the read operation retrieves only 8192 bytes.
  • Increase the input bufferlength to exceed 24576 bytes.
  • Observe that the program enters an infinite wait with no output and does not exit.

Expected Behavior:

  • The buffer and echo should be equal, meaning the data written should match the data read without any loss or corruption.

Test Code:

use std::io::{BufReader, Read, Write};
use std::net::TcpStream;

fn main() -> std::io::Result<()> {
    let mut stream = BufReader::new(TcpStream::connect("cat")?);
    let buffer = vec![0x12; 16384];
    stream.get_mut().write_all(buffer.as_ref())?;

    let mut echo = vec![0u8; 16384];

    let mut b = BufReader::new(stream);
    b.read(&mut echo)?;
    let mut i = 0;
    for v in echo {
        if v == 0u8 {
            println!("index: {:?}", i);
            break;
        }

        i += 1;
    }

    Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant