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

Error when parsing !DOCTYPE longer than buffer of BufRead #801

Closed
BlueGreenMagick opened this issue Sep 19, 2024 · 1 comment · Fixed by #802
Closed

Error when parsing !DOCTYPE longer than buffer of BufRead #801

BlueGreenMagick opened this issue Sep 19, 2024 · 1 comment · Fixed by #802

Comments

@BlueGreenMagick
Copy link
Contributor

BlueGreenMagick commented Sep 19, 2024

Description

When parsing <!DOCTYPE []> from a BufRead, there is a bug where it thinks a closing tag '>' that occurs as part of the doctype instead closes the DOCTYPE. This occurs when the entire doctype does not fit inside the bufread's buffer.

Because of that, when a closing tag '>' is mistakenly parsed as end of doctype, the content after that is parsed incorrectly.

Steps to reproduce

use quick_xml::events::Event;
use quick_xml::Reader;
use std::io::BufReader;

fn main() {
    let xml = r#"<!DOCTYPE X [<!-- comment --><!ENTITY a "a">]>"#;
    let reader = BufReader::with_capacity(4, xml.as_bytes());
    let mut xml_reader = Reader::from_reader(reader);
    let mut buf = vec![];
    loop {
        match xml_reader.read_event_into(&mut buf).unwrap() {
            Event::Eof => break,
            _ => {}
        }
    }
    println!("Parsed xml without error");
}

Above code throws an error Syntax(InvalidBangMarkup). This is because the closing tag for comment <!-- comment --> is mistakenly parsed as closing doctype, and so trying to parse <!ENTITY> throws an error.

However, things work fine if we increase the bufreader capacity to greater than text content (e.g. 1024).

I'll be opening a PR for the fix right away

@Mingun
Copy link
Collaborator

Mingun commented Sep 19, 2024

Yes, that is a known bug #590. I close this as duplicate.

@Mingun Mingun closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants