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

C implementation of xml.etree.ElementTree does not make a copy of attrib argument when creating new Element #80866

Open
GPHemsley mannequin opened this issue Apr 21, 2019 · 4 comments
Labels
3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir topic-XML type-bug An unexpected behavior, bug, or error

Comments

@GPHemsley
Copy link
Mannequin

GPHemsley mannequin commented Apr 21, 2019

BPO 36685
Nosy @scoder, @bitdancer, @asvetlov, @serhiy-storchaka, @srinivasreddy, @JulienPalard, @pganssle, @GPHemsley
PRs
  • bpo-32424: Improve test coverage for xml.etree.ElementTree #12891
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2019-04-21.00:07:40.396>
    labels = ['expert-XML', '3.8', 'type-bug', 'library', '3.9']
    title = 'C implementation of xml.etree.ElementTree does not make a copy of attrib argument when creating new Element'
    updated_at = <Date 2019-04-21.21:41:30.102>
    user = 'https://github.com/GPHemsley'

    bugs.python.org fields:

    activity = <Date 2019-04-21.21:41:30.102>
    actor = 'gphemsley'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'XML']
    creation = <Date 2019-04-21.00:07:40.396>
    creator = 'gphemsley'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36685
    keywords = ['patch']
    message_count = 4.0
    messages = ['340590', '340591', '340598', '340599']
    nosy_count = 9.0
    nosy_names = ['scoder', 'r.david.murray', 'eli.bendersky', 'asvetlov', 'serhiy.storchaka', 'thatiparthy', 'mdk', 'p-ganssle', 'gphemsley']
    pr_nums = ['12891']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36685'
    versions = ['Python 2.7', 'Python 3.8', 'Python 3.9']

    @GPHemsley
    Copy link
    Mannequin Author

    GPHemsley mannequin commented Apr 21, 2019

    In the process of investigating and writing tests for bpo-32424, I discovered that the C implementation of xml.etree.ElementTree does not make a copy of the attrib argument when creating a new element, allowing the attributes of the element to be modified outside of creation.

    The Python implementation does not have this problem.

    @GPHemsley GPHemsley mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir topic-XML type-bug An unexpected behavior, bug, or error labels Apr 21, 2019
    @GPHemsley
    Copy link
    Mannequin Author

    GPHemsley mannequin commented Apr 21, 2019

    My proposed solution to this was to make a copy of the attrib dictionary in the create_new_element() method in the C implementation, which solves the problem. However, this was apparently objected to on the grounds of performance.

    Not knowing C very well, any guidance on a better way to fix this would be appreciated. :)

    @scoder
    Copy link
    Contributor

    scoder commented Apr 21, 2019

    Instead of always copying the dict in create_new_element(), we should make sure that all code that calls that function (directly or indirectly) does so with a safely owned dict. If that means that we need to add dict copying in some other place, then that's what's needed to fix this bug.

    The best fix is to make the copy close to the user input, where we know what we received and how we will continue to use it.

    @scoder
    Copy link
    Contributor

    scoder commented Apr 21, 2019

    Given that this has probably been like this forever, and thus provably doesn't hurt very much, I would argue that it's not worth fixing this in Py3.7. Not sure about Py2.7, but I think the answer there should be a no, too.

    @scoder scoder removed the 3.7 (EOL) end of life label Apr 21, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir topic-XML type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant