Revert "fail with size limit on large maps too"

This reverts commit ce286b2519.
This commit is contained in:
Ty Overby 2015-05-29 13:39:17 -07:00
parent ce286b2519
commit e8d783fdfc
2 changed files with 4 additions and 23 deletions

View File

@ -354,15 +354,7 @@ impl<'a, R: Read> Decoder for DecoderReader<'a, R> {
fn read_map<T, F>(&mut self, f: F) -> DecodingResult<T>
where F: FnOnce(&mut DecoderReader<'a, R>, usize) -> DecodingResult<T>
{
use std::mem::size_of;
use std::usize;
let len = try!(self.read_usize());
if let SizeLimit::Bounded(x) = self.size_limit {
if (len > usize::MAX / size_of::<T>()) ||
(len * size_of::<T>()) as u64 > (x - self.read) {
return Err(DecodingError::SizeLimit)
}
}
f(self, len)
}
fn read_map_elt_key<T, F>(&mut self, _: usize, f: F) -> DecodingResult<T>

View File

@ -335,20 +335,9 @@ fn no_oom() {
}
let x = encode(&FakeVec { len: 0xffffffffffffffffu64, byte: 1 }, Bounded(10)).unwrap();
{
let y : Result<Vec<u8>, _> = decode_from(&mut Cursor::new(&x[..]), Bounded(10));
match y {
Err(DecodingError::SizeLimit) => assert!(true),
_ => assert!(false)
}
}
{
let y : Result<HashMap<u8, u8>, _> = decode_from(&mut Cursor::new(&x[..]), Bounded(10));
match y {
Err(DecodingError::SizeLimit) => assert!(true),
_ => assert!(false)
}
}
}