-
Notifications
You must be signed in to change notification settings - Fork 181
Open
Description
I am writing an application that needs to read a zlib stream of bytes and it should only succeed once the whole stream of valid bytes is received. Every time a new byte is read from the stream, I append to a vector of bytes an call something like this:
let mut z = ZlibDecoder::new(&bytes[..]);
let mut s = String::new();
z.read_to_string(&mut s)?;
I was expecting the read_to_string
call to keep failing until the whole valid stream is received, but ZlibDecoder
seems to always succeed when the bytes are in some valid range.
Example:
#[test]
pub fn test_invalid_input() {
let bytes:Vec<u8> = vec![77];
let mut z = ZlibDecoder::new(&bytes[..]);
let mut s = String::new();
let result = z.read_to_string(&mut s);
assert!(result.is_err());
}
#[test]
pub fn test_invalid_input() {
let bytes:Vec<u8> = vec![1,1,1,1];
let mut z = ZlibDecoder::new(&bytes[..]);
let mut s = String::new();
let result = z.read_to_string(&mut s);
assert!(result.is_err());
}
The first test fails, while the second succeed. I was expecting both tests to fail since both inputs are not valid zlib data.
Metadata
Metadata
Assignees
Labels
No labels