Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix overflow issue found with fuzz #54

Merged
merged 2 commits into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
}
}
}