deserialization: Handle read length of zero from Read

This commit is contained in:
George Hilliard committed 2020-05-09 15:42:08 -05:00
1 parent 5b7d304a39
commit 4aaec0d72c
1 file changed
+5 -2
+5 -2
View File
@@ -1,5 +1,5 @@
use err_derive::Error;
use log::error;
use log::*;
use nom::IResult;
use nom::{bytes::streaming::take, number::streaming::*, combinator::*, sequence::*};
use std::io::Read;
@@ -53,7 +53,10 @@ fn read_from_reader<P, O, E, R>(mut parser: P, mut rdr: R) -> Result<O, E>
Err(e) => return Err(e.into()),
};
(&mut rdr).take(to_read as u64).read_to_end(&mut input)?;
if 0 == (&mut rdr).take(to_read as u64).read_to_end(&mut input)? {
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof,
"Read returned 0 bytes").into());
}
}
}