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

Reading a DataFrame succeeds even if it is incomplete #119

Closed
neivv opened this issue Apr 29, 2017 · 2 comments · Fixed by #128
Closed

Reading a DataFrame succeeds even if it is incomplete #119

neivv opened this issue Apr 29, 2017 · 2 comments · Fixed by #128
Labels

Comments

@neivv
Copy link

neivv commented Apr 29, 2017

If DataFrame::read_dataframe is passed too few bytes, it will still succeed and return a dataframe with an incomplete payload.

Example:

    use websocket::DataFrame;
    let mut data = vec![0x8au8, 0x08, 0x19, 0xac, 0xab, 0x8a, 0x52, 0x4e, 0x05, 0x00];
    println!("Incomplete header:\n  {:?}", DataFrame::read_dataframe(&mut &data[..1], false));
    // This doesn't make sense
    println!("Incomplete payload:\n  {:?}", DataFrame::read_dataframe(&mut &data[..6], false));
    println!("Complete dataframe:\n  {:?}", DataFrame::read_dataframe(&mut &data[..], false));
    data.push(0xff);
    println!("Additional data:\n  {:?}", DataFrame::read_dataframe(&mut &data[..], false));

outputs

Incomplete header:
  Err(NoDataAvailable)
Incomplete payload:
  Ok(DataFrame { finished: true, reserved: [false, false, false], opcode: Pong, data: [25, 172, 171, 138] })
Complete dataframe:
  Ok(DataFrame { finished: true, reserved: [false, false, false], opcode: Pong, data: [25, 172, 171, 138, 82, 78, 5, 0] })
Additional data:
  Ok(DataFrame { finished: true, reserved: [false, false, false], opcode: Pong, data: [25, 172, 171, 138, 82, 78, 5, 0] })
@illegalprime
Copy link
Collaborator

illegalprime commented Apr 29, 2017

Thank's for the issue, the problem seems to be here. This only happens when you give it a non-blocking reader such as a &mut [u8], when reading from a TcpStream or similar it should block until it gets the amount of data in the header length.

With the "Additional Data" test you should see that you have 0xff leftover in your buffer. I think the only issue here is the "Incomplete Payload" scenario and it can be fixed by changing read_to_end to read_exact.

@illegalprime
Copy link
Collaborator

I have exams right now so I can't get to it, but a PR is always welcome 😉

illegalprime pushed a commit that referenced this issue May 29, 2017
Dataframe reads all of payload. Fixes #119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants