Skip to content

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

Open

Description

@GPHemsley
mannequin
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']

    Linked PRs

    Activity

    1. GPHemsley commented on Apr 21, 2019

      GPHemsleymannequin
      MannequinAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Apr 21, 2019
    3. GPHemsley commented on Apr 21, 2019

      GPHemsleymannequin
      MannequinAuthor

      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. :)

    4. scoder commented on Apr 21, 2019

      @scoder
      Contributor

      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.

    5. scoder commented on Apr 21, 2019

      @scoder
      Contributor

      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.

    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)end of life3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions