Skip to content

pyexpat: ExternalEntityParserCreate does not propagate the reparse-deferral setting #154738

Description

@tonghuaroot

Bug description

xmlparser.ExternalEntityParserCreate() copies the parent parser's fields onto the new subparser, but misses reparse_deferral_enabled. Since PyObject_GC_New does not zero the struct, that field is read uninitialized, so GetReparseDeferralEnabled() on the subparser returns a garbage value.

from xml.parsers import expat

p = expat.ParserCreate()
p.SetReparseDeferralEnabled(False)
sub = p.ExternalEntityParserCreate(None)
print(sub.GetReparseDeferralEnabled())  # True, should be False

Expat's own C-level state is inherited correctly (parserCreate saves and restores it), so the actual parsing behaviour is fine; only the Python-visible cached value is wrong.

CPython versions tested on

3.13, 3.14, main

Operating systems tested on

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions