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

Parse errors leaking from XML::Reader #12649

Closed
straight-shoota opened this issue Oct 23, 2022 · 0 comments · Fixed by #12663
Closed

Parse errors leaking from XML::Reader #12649

straight-shoota opened this issue Oct 23, 2022 · 0 comments · Fixed by #12663
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:serialization

Comments

@straight-shoota
Copy link
Member

straight-shoota commented Oct 23, 2022

When reading an invalid document with XML::Reader, parser errors remain stored and are falsely attributed to subsequent parses.

Example:

require "xml"

reader = XML::Reader.new(%(</foo>)) # Invalid XML
reader.read
reader.expand?

xml = XML.parse(%(<people></people>))
xml.errors # => [#<XML::Error:StartTag: invalid element name>]

A reason for that is that the XML::Reader instance is never closed to clean up. It does not even provide a method for doing that.

And even then there's the problem of global error state in libxml2. If multiple XML::Reader instance are intermingled (or an XML::Reader with XML.read), errors would be totally messed up.

A simple solution for the problem demonstrated above would be to reset errors in XML.parse and its sister methods. These methods are self-contained, so the error state could even be reset to what it was before. This would preserver functionality when called within an outer XML::Reader "session".
There's no solution for intermingled XML::Reader instances though.

This bug was discovered through spec randomization in #12541 (https://github.com/crystal-lang/crystal/actions/runs/3303805339/jobs/5452171721).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:serialization
Projects
None yet
1 participant