From 38058fb6d3cf7ee2adfd8dfafe22314df827d779 Mon Sep 17 00:00:00 2001 From: Francesco Mazzoli Date: Sat, 3 Jan 2015 04:54:31 +0100 Subject: [PATCH] Perform sanity check when reading enum variant. --- src/reader.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index 6c04648..2cc0cb1 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -74,10 +74,18 @@ impl<'a, R: Reader+Buffer> Decoder for DecoderReader<'a, R> { F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult { f(self) } - fn read_enum_variant(&mut self, _: &[&str], mut f: F) -> IoResult where + fn read_enum_variant(&mut self, names: &[&str], mut f: F) -> IoResult where F: FnMut(&mut DecoderReader<'a, R>, uint) -> IoResult { let id = try!(self.read_uint()); - f(self, id) + if id >= names.len() { + Err(IoError { + kind: OtherIoError, + desc: "out of bounds tag when reading enum variant", + detail: Some(format!("Expected tag < {}, got {}", names.len(), id)) + }) + } else { + f(self, id) + } } fn read_enum_variant_arg(&mut self, _: uint, f: F) -> IoResult where F: FnOnce(&mut DecoderReader<'a, R>) -> IoResult {