Skip to content

xmlrpc.client: quadratic memory use with nested string elements #162285

Description

@woodruffw

Bug report

Filing this as a normal bug per xmlrpc.client's security note.

TL;DR: Unmarshaller.end keeps a fragment buffer that it doesn't clear when handling nested tags, leading to quadratic memory growth:

return f(self, "".join(self._data))

This means that loads(...) observes duplicate values with (for example) nested <string> tags:

from xmlrpc.client import loads

packet = (
    "<methodResponse><params><param><value>"
    "<string><string>a<![CDATA[b]]></string></string>"
    "</value></param></params></methodResponse>"
)
values, _ = loads(packet)
print(values)

The above prints ('ab', 'ab') despite there being only one ab in the payload.

I'm pretty sure the fix for this is just:

data = "".join(self._data)
self._data.clear()
return f(self, data)

i.e. compute the joined version and then clear the fragment buffer rather than keeping it around to grow.

One wrinkle: this does change the observable outcome with the loads(...) API: the example above becomes ('ab', None). I actually think this is more correct anyways, since XML-RPC has no semantics for nested scalars like <string>.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. woodruffw commented on Nov 19, 2026

    @woodruffw
    ContributorAuthor

    Note: another option here would be to reject these kinds of nested scalar tags, but I think that would be a larger compatibility question.

  2. woodruffw commented on Nov 19, 2026

    @woodruffw
    ContributorAuthor

    Opened #162287 for this.

  3. added
    performancePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 20, 2026
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

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions