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

Text events are not emitted when text node ends exactly at BufferedReader buffer border #774

Closed
randomdude999 opened this issue Jun 29, 2024 · 1 comment · Fixed by #775
Labels

Comments

@randomdude999
Copy link

Perhaps the title isn't quite clear here. As a concrete example, the document written by this python script:

open('test.xml', 'w').write('<asdf>' + 'a' * (8192 - 6) + '</asdf>')

(i.e., a document with a single tag, whose contents end at offset 8192) will cause quick-xml to emit only a Start and End event, with no Text event in the middle. This can be verified with the following rust program, which simply dumps all received events to stderr:

use quick_xml::events::Event;
use quick_xml::reader::Reader;

fn main() {
    let mut reader = Reader::from_file("test.xml").unwrap();
    let mut buf = Vec::new();
    loop {
        let ev = reader.read_event_into(&mut buf);
        if matches!(ev, Ok(Event::Eof)) { break; }
        dbg!(&ev);
    }
}

This prints:

[src/main.rs:10:9] &ev = Ok(
    Start(
        BytesStart { buf: Borrowed("asdf"), name_len: 4 },
    ),
)
[src/main.rs:10:9] &ev = Ok(
    End(
        BytesEnd { name: Borrowed("asdf") },
    ),
)

The root cause seems to be in the read_text of buffered_reader.rs. In this case, reading the text data requires two loop iterations. On the first iteration, < is not found in the data, so the entire data is pushed onto buf and the loop continues. On the second iteration, < is found at position 0, which triggers the special case in the code that returns ReadTextResult::Markup instead of ReadTextResult::UpToMarkup, and does not indicate that text data was also present.

I think the right fix here would be to only check the zero-position case on the first iteration of the loop.

@Mingun Mingun added the bug label Jun 29, 2024
Mingun added a commit to Mingun/quick-xml that referenced this issue Jun 29, 2024
failures (2):
  async-tokio (1):
    issue774
  issues (1):
    issue774
dralley pushed a commit that referenced this issue Jun 29, 2024
failures (2):
  async-tokio (1):
    issue774
  issues (1):
    issue774
@Mingun
Copy link
Collaborator

Mingun commented Jun 29, 2024

I just released 0.35.0 with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants