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 bound tests in read_bang #95

Merged
merged 2 commits into from
Sep 23, 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
7 changes: 5 additions & 2 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,16 @@ impl<B: BufRead> Reader<B> {

/// reads `BytesElement` starting with a `!`,
/// return `Comment`, `CData` or `DocType` event
///
/// Note: depending on the start of the Event, we may need to read more
/// data, thus we need a mutable buffer
fn read_bang<'a, 'b>(
&'a mut self,
buf_start: usize,
buf: &'b mut Vec<u8>,
) -> Result<Event<'b>> {
let len = buf.len();
if len >= 3 && &buf[buf_start + 1..buf_start + 3] == b"--" {
if len >= buf_start + 3 && &buf[buf_start + 1..buf_start + 3] == b"--" {
let mut len = buf.len();
while len < 5 || &buf[len - 2..] != b"--" {
buf.push(b'>');
Expand All @@ -301,7 +304,7 @@ impl<B: BufRead> Reader<B> {
Ok(Event::Comment(
BytesText::borrowed(&buf[buf_start + 3..len - 2]),
))
} else if len >= 8 {
} else if len >= buf_start + 8 {
match &buf[buf_start + 1..buf_start + 8] {
b"[CDATA[" => {
let mut len = buf.len();
Expand Down
17 changes: 17 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,20 @@ fn fuzz_53() {
}
}
}

#[test]
fn test_issue94() {
let data = br#"<Run>
<!B>
</Run>"#;
let mut reader = Reader::from_reader(&data[..]);
reader.trim_text(true);
let mut buf = vec![];
loop {
match reader.read_event(&mut buf) {
Ok(quick_xml::events::Event::Eof) | Err(..) => break,
_ => buf.clear(),
}
buf.clear();
}
}