Skip to content

Commit

Permalink
fix overflow issue found with fuzz (#54)
Browse files Browse the repository at this point in the history
* fix overflow issue found with fuzz

* update dev dependencies
  • Loading branch information
tafia committed Mar 6, 2017
1 parent 0fd7fbb commit 2745899
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ encoding_rs = "0.4.0"
error-chain = "0.9.0"

[dev-dependencies]
xml-rs = "0.3.8"
xml-rs = "0.4.1"

[lib]
bench = false
2 changes: 1 addition & 1 deletion src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl<B: BufRead> Reader<B> {
// TODO: do this directly when reading bufreader ...
let len = buf.len();
let name_end = buf.iter().position(|&b| is_whitespace(b)).unwrap_or(len);
if buf[len - 1] == b'/' {
if let Some(&b'/') = buf.last() {
let end = if name_end < len { name_end } else { len - 1 };
if self.expand_empty_elements {
self.tag_state = TagState::Empty;
Expand Down
15 changes: 15 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extern crate quick_xml;
use quick_xml::reader::Reader;
use quick_xml::events::Event::*;
use quick_xml::events::attributes::Attribute;
use std::io::Cursor;

#[test]
fn test_sample() {
Expand Down Expand Up @@ -298,3 +299,17 @@ fn test_koi8_r_encoding() {
}
}
}

#[test]
fn fuzz_53() {
let data : &[u8] = b"\xe9\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n(\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00<>\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00<<\x00\x00\x00";
let cursor = Cursor::new(data);
let mut reader = Reader::from_reader(cursor);
let mut buf = vec![];
loop {
match reader.read_event(&mut buf) {
Ok(quick_xml::events::Event::Eof) | Err(..) => break,
_ => buf.clear(),
}
}
}

0 comments on commit 2745899

Please sign in to comment.