Revert "Merge pull request #42 from jmesmon/fix-oom"

This reverts commit 1c3f457cf9, reversing
changes made to 84b5c416ca.
This commit is contained in:
Ty Overby 2015-05-29 13:50:16 -07:00
parent e8d783fdfc
commit fd52ae0d64
2 changed files with 0 additions and 26 deletions

View File

@ -335,15 +335,7 @@ impl<'a, R: Read> Decoder for DecoderReader<'a, R> {
fn read_seq<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_seq_elt<T, F>(&mut self, _: usize, f: F) -> DecodingResult<T>

View File

@ -323,21 +323,3 @@ fn test_slicebox() {
fn test_multi_strings() {
assert!(encode(&("foo", "bar", "baz"), Infinite).is_ok());
}
#[test]
fn no_oom() {
use std::io::Cursor;
#[derive(RustcEncodable)]
struct FakeVec {
len: u64,
byte: u8
}
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)
}
}