fortanix / rust-sgx

The Fortanix Rust Enclave Development Platform
https://edp.fortanix.com
Mozilla Public License 2.0
421 stars 99 forks source link

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

Open yingjun-wu opened 4 weeks ago

yingjun-wu commented 4 weeks ago

https://github.com/fortanix/rust-sgx/blob/b6f0262614ce1574b7d66226b68d7247b822d860/examples/usercall-extension/app/src/main.rs#L5-L12

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

Steps to Reproduce:

Use the provided test code.

Expected Behavior:

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(())
}